I am writing C and C++ code on Linux OS and I am using GCC. After finishing my code, I would like to generate an ELF file. I just can generate "a.out" file and I don't need it. How can I get ELF file ? ELF file occurs as a result of what ? or Is it possible to generate this file with this program ?
Asked
Active
Viewed 4.6k times
16
-
5The a.out is an ELF file. – Douglas Leeder Feb 10 '14 at 22:59
-
Possible duplicate of [Creating ELF instead of a.out](http://stackoverflow.com/questions/5565594/creating-elf-instead-of-a-out) – Ciro Santilli OurBigBook.com Apr 14 '16 at 08:22
1 Answers
35
The compiler (i.e. gcc or g++) will invoke the linker (ld) which produces an ELF executable.
In practice, you will use a builder program (like make) to drive gcc commands. See this answer.
The default output file for gcc is still named a.out (for historical reasons) but is an ELF file. And you really want to ask gcc to output an executable with a more fancy name.
Simple example, you code a single-file hello-world.c program. You can compile it with e.g.
gcc -Wall -g hello-world.c -o hello-world-bin
(order of arguments to gcc matters a lot!)
and the produced hello-world-bin is an ELF executable. Check with
file hello-world-bin
then run it with
./hello-world-bin your arguments to it
Later, learn how to use the gdb debugger on it.
Community
- 1
- 1
Basile Starynkevitch
- 223,805
- 18
- 296
- 547