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 ?
To generate ELF production file, first combine the bootloader and application firmware HEX files in a single HEX file. To combine the bootloader and application HEX files, use a command line tool like srec_cat (http://srecord.sourceforge.net/). This tool is part of the srecord utilities that are available with WinAVR.
gcc produces executable files in the ELF file format. you can use readelf and objdump to read parts of an elf file. You can also use 'hexdump filename' to get a hexdump of the contents of a binary file (this is likely only useful if you like reading machine code or you are writing an assembler).
To find them the ELF header is used, which is located at the very start of the file. The first bytes contain the elf magic "\x7fELF" , followed by the class ID (32 or 64 bit ELF file), the data format ID (little endian/big endian), the machine type, etc. Finally, the entry point of this file is at address 0x0.
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.
See also this and that answers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With