简体   繁体   中英

ELF File generation commands and options

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.

The option -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 -c option.

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 -o option:

$ gcc test.c -o myprogram

The above commands names the executable program myprogram .

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM