1.5. Change the generated file name¶
As we saw in Basic Compilation, a.out
is meaningless. Basically, every similar good_morning_world.c
, good_evening_world.c
would also generate a.out
. To make things more obvious, it makes sense that the output of hello_world.c
is hello_world
To compile that file with GCC so that hello_world
is generated, instead of running as in Basic Compilation:
gcc hello_world.c
the command would be:
gcc hello_world.c -o hello_world
The compiler flag -o
gives the directive to select the generated output file name.
Similar to how it was done earlier, to execute the binary generated from the source file, the command would then be as shown below.
./hello_world
If everything went fine, the output would be:
Hello World!
1.5.1. Change the generated file name - MSVC¶
To compile on windows with Microsoft Visual C Compiler cl.exe, the command would be:
cl.exe hello_world.c /nologo /Fegreeting.exe
We use the compiler option /nologo
to reduce amount of information printed on screen. And we also use the compiler option /Fe
to select the output executable file name.
hello_world.c
As you can see above, since we used the compiler option /nologo
, cl.exe is now silent and it only prints the name of file it is compiling. When the above command completes successfully, file greeting.exe
is generated in the same directory.
To run the generated binary, we can as shown below:
call greeting.exe
The output would be same as that we would have got when compiled with gcc:
Hello World!