I am learning C in Linux Mint, so I made a directory in which I place my programs. Whenever I compile a program, everytime a.out
is being over-written with the new compiled program.
For ex. To compile a hello.c
file I run command: cc hello.c
, Now this program will create a.out
, but I want it to be hello.out
Why is it?
How can I compile so that hello.c should create hello.out file?

- 83
- 1
- 1
- 7
3 Answers
Why only a.out is being created everytime when I make different programs in directory?
Because that's the default behavior of your compiler.
How can I compile so that hello.c should create hello.out file?
In general, refer to the documentation for the compiler you're using, which will tell you how to do this.
Assuming you're using gcc
or similar, it's the -o
option:
gcc hello.c -o hello.out

- 1,031,962
- 187
- 1,923
- 1,875
-
Why everytime a.out is created? Is it Unix tradition? – Pr4njal Oct 06 '16 at 06:41
-
because you haven't specify the output filename – phuclv Oct 06 '16 at 06:48
-
@Pr4njal: Again: *"Because that's the default behavior of your compiler."* Yes, I think it dates back many, many years to the earliest `cc` on Unix. Remember that you can list several C files on the command line and have them all compiled into one program. (FWIW, I can tell you that even in 1990, Borland's C compiler for DOS had a different default [based on the first source filename, I think].) – T.J. Crowder Oct 06 '16 at 07:15
Default execution in Unix/Linux is a.out
file. If you create your own executable then compile program like:
cc hello.c -o hello.out
./hello.out // manually created executable file
or
cc hello.c -o hello
./hello // manually created executable file
Unix/Linux doesn't care about extensions. -o hello
basically your suggested name for the executable file that gcc
would create.
Why every time a.out is created?
a.out
remains the default output file name for executables created by certain compilers/linkers when no output name is specified, even though these executables are no longer in the a.out
format.
Please see the wiki page of a.out.

- 33,420
- 29
- 119
- 214
Share your compilation command. In the compilation command you can mention what the name of the output binary file, like: "gcc hello.c -o hello" then the binary file name will be (hello) because you mention after flag "-o" that you want to name the output file by the name "hello". If you don't add the flag "-o" with a name, then the default name for the binary file is "a.out".

- 730,956
- 141
- 904
- 1,278

- 143
- 1
- 4