Gccgnu c Compiler)
If an error occurs in Linux for the first time, please leave a message to specify criticism.
1. gcc can compile executable programs on multiple hardware platforms, and its execution efficiency is 20% to 30% higher than that of the general compiler.
2. The GCC compiler can compile and link source programs and assembler programs in C and C ++ into executable files.
3. in Linux, the executable file does not have a uniform suffix. The system distinguishes the executable file from the non-Executable File Based on the file attributes.
GCC uses suffixes to differentiate file categories:
. C: C language source code file
.: Library file consisting of the target file
. C. Cc,. cxx: C ++ source code file
. H: Header file
. I: C source code files that have been preprocessed
. Ii: C ++ source code files that have been preprocessed
. O: Target file after compilation
. S: Assembly language code file
. S: Compiled assembly language code files
First Program
Hello. c
#include<stdio.h>int main(void){ printf("hello world!\n"); return 0; }
Compile command
# Gcc hello. c-o hello
Run commands
#./Hello
Running result:
Hello world!
Gcc basic usage: gcc [options] [filename]
Options: Compilation options required by the compiler
Filename: name of the file to be compiled
-OOutput_filename: Compile the name of the executable file. If this option is not specified, the system will provide the preset Executable File a. out.
-COnly compile and not connect to an executable file, and generate the target file with the. o suffix.
-GGenerate the necessary symbolic information for the debugging tool. This option is required for program debugging.
-OThe program execution speed will be greatly improved after the program compilation and connection process is optimized and optimized)
-I dirname: Add the directory specified by dirname to the program header file directory list.
The C program header file contains two scenarios: # include <x. h>
# Include "x. h"
For the <> Preprocessing Program, search for the corresponding files in the system preset header file directory, such as/usr/include)
"" If the required file is not found in the current directory, search for it in the specified dirname directory.
-L dirname:Add the directory specified by dirname to the library file directory list. In the default state, The Connection Program ld searches for the required library files in the system's preset path, such as/usr/lib) first in the directory specified by-L, then go to the system preset path to search for it.
-LConnect to libraries in lib
-Static: Static Link Library File
The library is divided into dynamic library and static library. The dynamic library uses the. so suffix static. a suffix.
When using the static library, find the required functions and the program copies them to the executable files.
The dynamic library leaves a "flag" in the executable program. When the program is running, it loads the dynamic library function.
Dynamic library is selected by default when linking in linux
For example, gcc-static hello. c-o hello
-WallGenerate all warning information
-WDo not generate warning
-DPre-compilation options