In the previous section we learned about the Vim editor, and then we learned about the GCC compiler together, where do we differentiate between editors and compilers?
Editor is that I use it to write programs (edit code), and we write code statements, the computer is not understand, we need to turn it into a computer can understand the statement, the compiler is such a conversion tool. That is, we use the editor to write programs, compiled by the compiler to run !
compilers are programs that translate advanced computer languages that are easy to write, read, and maintain into low-level machine languages that computers can interpret and run.
GCC (GNU Compiler Collection,gnu Compiler Suite), a programming language compiler developed by GNU. As the official compiler for the GNU operating system, GCC has now been adopted as a standard compiler for most Unix-like operating systems (such as Linux, BSD, Mac OS X, etc.), and GCC is also applicable to Microsoft Windows.
GCC was originally used to compile the C language, and with the development of the project GCC has become a compiler that can compile the C, C + +, Java, Ada, Fortran, object C, Object + C, Go languages.
this is just Simple Introduction how to compile C programs or C + + programs to eventually become an executable program .
GCC recognizes the following file name extensions :
. C C language files
. I pre-preprocessed C language files
. C,. CC,. CP,. cpp,. C + +,. cxx C + + language files
. II C + + language files after preprocessing
. S assembly file (user's own new assembly file)
. s pre-processing assembly files
. o the compiled target file
. A static link library for target files (used when linking)
dynamic-link libraries for. So target files (link, run-time use)
Compilation process for GCC and g++ compilers
1. pretreatment
2. Compiling
3. Compilation
4. Links
GCC Common Compilation Application Example
Step into the compilation:
1) gcc-e Hello.c-o hello.i
2) gcc-s Hello.i-o Hello.s
3) gcc-c Hello.s-o hello.o
4) GCC Hello.o-o hello_elf
description of the compilation options :
-O file specifies that the generated output file is named file
-e only for preprocessing
-S only for preprocessing and compiling
-C only preprocess, compile, and assemble
filename suffix Description :
. C C language Files
. I Pre-preprocessed C language files
. s pre-processing assembly files
. o the compiled target file
After the program compiles successfully, run the executable program through "./".
Common compilations (or processes that are pre-processed, compiled, compiled, linked):
GCC Hello.c-o Demo
In the case of C + + code, simply use the g++ compiler instead.
If you do not have a g++ compiler, you can install it online:
Compile the C + + program using g++ :
Some other options for GCC, g++ compilation
- v Displays the configuration command when making the GCC tool, showing the preprocessor, the compiler version number
-wall generate warning messages for all levels
- W turn off all warnings, we recommend that you do not use this option
-idir The dir directory is added to the header file to search the directory list, preferably in the Dir directory to find the included header file
-ldir Add dir directory to library file directory list, first find library file in dir directory
-lname Library with link library as name
-static use static libraries when linking
-shared compiling a dynamic library
Please click here to download the example code for use.
Building and using the--linux compiler in the Linux development environment GCC