Home > Operation and Maintenance > Linux Operation and Maintenance > How to compile c language in linux

How to compile c language in linux

王林
Release: 2019-12-06 10:23:17
Original
6882 people have browsed it

How to compile c language in linux

C program compilation under Linux system:

gcc -Wall -g -o tfP tfP.c
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template