Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

generating a.out file format with gcc

How do I generate the a.out file format with GCC on x86 architectures?

With NASM I can do this easily with the -f flag, for example:

nasm -f aout start.asm
objdump -a start.o

start.o:     file format a.out-i386-linux
start.o

On Linux, compiling .c files produces an ELF object file. How can I produce a.out files with GCC?

like image 856
Nulik Avatar asked Nov 28 '11 22:11

Nulik


People also ask

Why does gcc compile to a out?

Without specifying an executable name (which can be done using the -o option), GCC defaults to storing the successfully compiled executable in a file called a. out .

How are out files generated?

An OUT file is a compiled executable file created by various source code compilers in Unix-like operating systems, such as Linux and AIX. It may store executable code, shared libraries, or object code. OUT files have been largely replaced by the newer COFF (Common Object File Format) format.

What is a .out file gcc?

a. out is the default executable name generated by the gcc . Once you invoke gcc a.


1 Answers

To generate the a.out format with gcc, your linker needs to be told to do so. You can do it by passing it flags from gcc thanks to the -Wl flag.

Here is what you would do for the a.out format:

gcc -Wl,--oformat=a.out-i386-linux file.c -o file.out

You can also display all formats supported by typing:

objdump -i
like image 120
Quentin Casasnovas Avatar answered Sep 21 '22 05:09

Quentin Casasnovas