gcc commonly used commands

gcc commonly used commands

Reference links: Linux C programming basics Loujia Peng
GCC compiler (Linux gcc command) 30 minutes Start Tutorial

A command format

gcc [-c|-S|-E] [-std=standard]
           [-g] [-pg] [-Olevel]
           [-Wwarn...] [-Wpedantic]
           [-Idir...] [-Ldir...]
           [-Dmacro[=defn]...] [-Umacro]
           [-foption...] [-mmachine-option...]
           [-o outfile] [@file] infile...

Second, the commonly used options

Options effect Examples
-E Perform only precompiled gcc -E hello.c -o hello.i
-S The C code into compiled gcc -S hello.i -o hello.s
-c Compile only perform operations without linking operations gcc -c hello.s -o hello.o
-The 指定生成的输出文件。If -o is not specified, the default is to put an executable file in a.out, the object file for source.suffix in source.o, its assembler file in source.s, a precompiled header file in source.suffix.gch, and all preprocessed C source on standard output.
-I (uppercase i) Specify the header file directory gcc main.c -I ../include -o main
-L Specify the directory where the file library gcc ../src/main.c -I ../include/head.h -L ../libs/ -l math
-l Specifies the program to link libraries gcc will be added in front of a static library name prefix lib, then additional static library file name extension .a get to find the static library file; additional extension DLL .so

Third, create a library

  • Static library
    1, input gcc -c -I/头文件目录 xxx.cgenerates .o file
    2, the input ar rcvs libxxx.a xxx.oto generate static library
  • DLL
    1, input gcc -fPIC -c -I/头文件目录 xxx.c.o files are generated

    -fPIC options applied to the compilation stage, tell the compiler to generate position independent code (Position-Independent Code); As a result, the generated code is no absolute address, the relative address all use, so the code can be loaded into the loader any location in memory, you can correct execution. This is the shared libraries required by the shared library is loaded, the location in memory is not fixed.
    2, the input gcc -shared -o libmath.so xxx.oto generate libraries

Guess you like

Origin www.cnblogs.com/20175211lyz/p/11565047.html