GCC in Linux
GCC is short for gnu c Compiler, but after so many years of development, GCC not only supports C language, he can also support Ada, CPP, Java, Objective C, Pascal, COBOL, and other languages. He also supports Functional Conversion into Mercury and other languages for logical programming. That is, he should now be short for the GNU Compiler Collection, that is, the GNU Compiler family.
However, the use of GCC can be basically divided into four steps: Preprocessing is also called pre-Compilation, that is, Preprocessing, Compilation is Compilation, Assembly is Assembly, and connection is Linking.
For preprocessing, we can use gcc-E test. c to output data to the screen, or use gcc-E test. c-o test. I to output data to the test. I file. For the-E option, the compiler can stop preprocessing and output preprocessing results.
For compilation, we can use. I file generation. s file. For example, we use gcc-S test. i-o test. o, in which the-S option of gcc indicates that the assembly code is stopped after it is generated during compilation, and-o outputs the assembly code file.
For assembly, the target file can be generated, such as the Command Format gcc-c test. c-o test. o.
For the connection, he is responsible for connecting the program's target file with all the additional target files required, and finally generating executable files, complex Target files include static and dynamic link libraries. We can use the gcc test. o-o test format.
For detection, we can use the-pedantic compilation option, for example, we use gcc-pedantic hello. the c-o hello format cannot ensure that the program is fully compatible with ansi c. We can use-Wall to generate more warning messages.
Although most functions in Linux place the header file in the/usr/include/directory by default, and the library file in the/usr/lib/directory, if we need other header files, the-I parameter is required. When we need other library files, use the-L parameter.
Library files in Linux are usually divided into dynamic link libraries (usually. so) and static link library (usually. end a), the difference is only that the Code required for program execution is dynamically loaded at runtime, or static load at compilation.
By default, GCC preferentially uses the dynamic link library for connection. we can add the-static parameter during compilation to force the use of the static Link Library.
Search Path sequence for static connections:
(1) ld will go to the parameter-L in the gcc command
(2) gcc environment variable LIBRARY_PATH
(3) set the directory, that is,/lib,/usr/lib,/usr/local/lib, which is also written in the program during gcc.
Search Path sequence for dynamic connections:
(1) the dynamic search path specified when the target code is compiled
(2) the dynamic search path specified by the Environment Variable LD_LIBRARY_PATH
(3) the dynamic search path specified in the configuration file/etc/ld. so. conf
(4) default dynamic library search path/lib
(5) default dynamic search path/usr/lib