How can I create an ELF file with GCC?

I write C and C ++ code on Linux and use GCC. After completing the code, I would like to create an ELF file. I can just generate the "a.out" file, and I don't need it. How can I get an ELF file? What is an ELF file? or is it possible to generate this file using this program?

+5
source share
1 answer

The compiler (i.e. gccor g++) will call the linker ( ld), which creates the ELF executable.

In practice, you will use a build program (for example make) to manage commands gcc. See this answer .

The default output file for gccis still called a.out(for historical reasons), but is an ELF file. And you really want to ask gccfor an executable file with a more bizarre name.

A simple example: you are a hello-world.cprogram hello-world.c. You can compile it, for example, with

 gcc -Wall -g hello-world.c -o hello-world-bin

(the order of the arguments gccis of great importance!)

and created hello-world-binis an ELF executable . Check with

 file hello-world-bin

then run it with

 ./hello-world-bin your arguments to it

Later you will learn how to use the debugger on it gdb.

.

+15

Source: https://habr.com/ru/post/1526248/


All Articles