Compiling C Code with GCC Compiler on Linux
Guide
Normally, for program development using C/C++, it’s recommended to use Visual Studio on Windows. However, when proceeding with simple tests, numerical calculations, simulations, etc., on Linux, the unique lightness of Linux can come as a significant advantage.
For example, if there is a C source code named infection_modified_200428.c
, try entering the following after moving to the corresponding path in the terminal.
gcc -o infection infection\_modified\_200428.c -lm
Then an executable file named infection
will be created in the same path, and it can be executed as follows.
./infection
In the gcc command, -o
stands for output, which is followed by the name of the file to be output. Together with a single space, it then takes the exact filename of the source code to be compiled.
The last -lm
likely stands for library math, indicating that a math library is used. It is important to note that even with the same command, there are instances where compilation fails if -lm
is not placed at the end.