C program compilation under Linux system:
gcc -Wall -g -o tfP tfP.c
Option description:
-Wall
represents the compiler during the compilation process A warning message (Warning
) will be output, for example, some variables are not used, the type pointed to by the pointer is wrong, the main function does not return an integer value, etc.
Although this kind of information is not an error and does not affect compilation, it is likely to be the source of program bugs. It can also help you find errors in the code and standardize the code format. Therefore, it is recommended to add the -Wall
parameter every time you compile.
Recommended online video tutorial: linux video tutorial
-g
means the compiler will collect debugging (debug
) information, In this way, if your program runs incorrectly, you can debug it line by line through tools such as gdb or lldb to easily find out the cause of the error. If you are not 100% sure that your program has no problems, it is recommended to add the -g
parameter. This will be much more convenient when debugging.
-o
means the compiler will output the compiled executable file to the folder you specify with the name you specify. The name after the space in -o is the name of the output file.
For example: -o is followed by test, which means that gcc will generate an executable file called test in my current directory after successful compilation. If this parameter is not added, the executable file generated after each compilation will be placed in the root directory and named a.out. After each successful compilation, the previous a.out file will be overwritten. Therefore, it is recommended to add the -o parameter to make it more organized.
Recommended related articles and tutorials: linux tutorial
The above is the detailed content of How to compile c language in linux. For more information, please follow other related articles on the PHP Chinese website!