1.2. Basic Compilation¶
Assuming there is a sample C source file, hello_world.c
as shown below, and we want to compile it.
#include <stdio.h>
int main() {
printf ("Hello World!\n");
return 0;
}
To compile that file with GCC (on Linux/Mac), the command would be.
gcc hello_world.c
When the above command completes successfully [1], file a.out
is generated in the same directory. Generally, the above command should remain silent and does not print any output on the console.
To execute the binary generated from the source file, the command would be as shown below [1].
./a.out
If everything went fine, the output would be:
Hello World!
1.2.1. Basic Compilation - MSVC¶
To compile on windows with Microsoft Visual C Compiler cl.exe, the command would be
cl.exe hello_world.c
When the above command completes successfully, file hello_world.exe
is generated in the same directory. The following output can be seen when we execute the above command.
Microsoft (R) C/C++ Optimizing Compiler Version 17.00.61030 for x86
Copyright (C) Microsoft Corporation. All rights reserved.
hello_world.c
Microsoft (R) Incremental Linker Version 11.00.61030.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:hello_world.exe
hello_world.obj
As you can see above, cl.exe is not so silent as the gcc. To make the output little more silent, in another section we will introduce the compiler option /nologo
You can run the generated binary with the following command:
call hello_world.exe
The output would be same as that we would have got when compiled with gcc:
Hello World!