compiler gcc in Linux environment
Gcc:
-O compilation chain delivered as executable
-O-O1-O2-O3 Compilation optimization
-G-G1-G2-G3 generating debug information to an executable file
-W Close all warnings
-W all,error-wall Show all warnings-werror put all warnings in error
-C Compile Build target file not linked
-E Pre-compilation
-S compiled into a compilation
-D Add a macro definition to the command line
-X The compilation type of the specified language gcc-x C xxxx.c gcc-x assembler Xxx.s
-STD=C89-STD=C99 compilation criteria for specified languages
Note: The GCC compiler automatically calls the linker ld
Restrict keyword int add (int* restrict a) {} optimize compiler compilation, pointer-to-value in function parameters in register, increase efficiency, support in C99, c89 not support
And then it's fun to compile the static library
Usually we need to call many library compilations, simple examples
Write a add.c save int add (int a,int b) {return a+b;}
Write a SUB.C subtraction function
Write a main.c call add,sub
Compiling gcc main.c add.c sub.c ====> a.out
When we write a lot of files, it seems very inconvenient, there is a static library generation
First step: Compile into the target file
Gcc-c-static ADD.C = = = "Target file add.o
Gcc-c-static sub.c=====> target file sub.o
Step two: Archive into a static library
Ar Tool came up
-R ar-r ku.a add.o SUB.O = = = Archive the target file as a static library ku.a
-T ar-t ku.a shows which target files your static library contains
NM tool (view function symbol functions)
NM target file/executable/static library/dynamic Library
Small application: * * * * use gcc static library, enter a diamond radius, print diamond
1. Write a RADIUS input library package Ioinput Library
2. Write a diamond-shaped print library to encapsulate the graphics library
Program: 1. Implement input 2. Implement Diamond 3. Compile into a static library 4. Call the static library
It's a fun ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.
Linux Environment Programming compiler tool and dynamic State Library