I was reading about ELF files on the net and am stuck in understanding a standard command to generate an ELF file.
Till now I have been running my code using > gcc test.c -o test.o .Thats it!!
One article says:
gcc -c test.c // will generate ELF file test.o
Now -o option is to tell the compiler to create an executable ( which is not ELF)
Another article says:
gcc -c test.c -o test.o // will generate ELF test.o -> here's where I am confused.
-o should always generate Executable.
Best How To :
-c tells GCC to generate an object file. This object file is only the compiled code from the source file
test.c, not a complete program. To generate a complete program you need to link the object file. Or not use the
-o option tells GCC what to name the output file, no matter what kind of output file it is.
So, to generate an executable file from a single source file, the simplest command is
$ gcc test.c
The above command will create an executable named
a.out in the current directory. To name the output file something else you use the
$ gcc test.c -o myprogram
The above commands names the executable program
To use the intermediate step with object files you use the
-c option, and then use a separate step to link the program, like
$ gcc -c test.c
$ gcc test.o -o myprogram
The above two commands is the same as the single command
gcc test.c -o myprogram.