Use gcc compiler

A, gcc compiler processes

GCC C compiler to compile a code, you need to go through the following four steps:

    pretreatment (Preprocessing): .c source file for preprocessing, generating .i file.
    Compilation (compilation): .i file compiled to generate .s assembly files.
    Compilation (assembly): to assemble .s files, generates .o object files.
    Links (linking): .o file to be linked to produce an executable file.

Two, gcc command

  2.1 gcc command format definition

       

   2.2 gcc commands commonly used parameters

    2.2.1 Basic parameters

      -E: preprocessed source file only, not compiled. The results output directly to the screen.

        

      -S: preprocessing of the source file, the compiler, without compilation. .S results saved in a file form, with the same name as the source .c files.

        

      -c: source file preprocessing, compilation, assembly, do not link to it. Save the results in a .o file format, with the same name as the source .c files.
        
      -save-temps: Save and compile all documents produced during the middle of. Intermediate file name with .c source file of the same name, suffix .i, .s, .o
        

          
    2.2.2 debugging parameters

      -o: any type of output are stored to the specified file.

        
      -Wall:打开编译器的警告标志,尽可能多的输出警告信息。强烈建议,编译时始终带上 -Wall 选项。
        
      -Werror:将所有的警告当成错误处理,必须消除警告才能继续编译。
        
   2.2.3 函数库参数

      -llibrary:手动指定函数库library参与链接。库名为library,文件名为liblibrary.a或liblibrary.so

      -Ldir:手动添加一个路径dir,用以搜索库文件(.a 或 .so 文件,即手动指定的函数库文件的所在目录)。

      -Idir:手动添加一个路径dir,用以搜索头文件(.h 文件,即源码内#include要包含的文件的所在目录)。

      

        

 

Guess you like

Origin www.cnblogs.com/zhengxunjie/p/11332427.html