In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
GCC and compilation process
GCC (GNU Compiler Colletion), the GUN compiler suite, is a set of programming language compilers developed by GNU. The GCC compiler under Linux system actually calls other different tools to complete preprocessing, compilation, assembly and linking work.
I. compilation process
In the eyes of the computer, there are only 1s and zeros. Unfortunately, the code we write in C cannot be understood by the computer directly. So if a program needs to be executed by a computer, it must be translated into 1s and zeros that can be read and executed by the computer. The process of achieving this result is called compilation.
Compilation includes the following steps: preprocessing, compilation, assembly, and linking. The specific process is as follows:
1. Preprocessing:
In the hello.c file, the preprocessing instructions (into # include,#define,#ifdef,#endif, etc.) are interpreted by the preprocessor, the preprocessing instructions are expanded or overwritten, the comments are deleted, and the necessary debugging information is added to generate the hello.i file.
The corresponding command is: gcc-E hello.c hello.i, which means that we only preprocess it.
two。 Compile
The .i file generated after preprocessor processing is still a text file and cannot be executed directly by the computer. In the compilation stage, the compiler needs to do lexical analysis, syntax analysis, and then generate the corresponding assembly file according to the hardware platform. Different hardware platforms have different compilers. For example, the compiler of x86 platform is very different from the assembly file generated by ARM cross-compiler, which is the most critical step for C language to realize cross-platform: compiling C code according to hardware platform.
Corresponding command: gcc-S hello.i hello.s
3. Compilation
For the compiled .s file, you need to continue processing to generate the .o file. Gcc calls the assembler as to translate the assembly source program into a relocatable file. A relocatable file means that although the file is an executable instruction stream of ELF, the global symbol has not yet been located. Because global symbols can appear in different files, their entry addresses need to be determined during compilation, so the last step, linking.
Corresponding command: gcc-c hello.s hello.o
4. Link
The assembled file cannot be run directly and needs to be linked to relocate the global symbol and merge the same segments. Usually, we need to use the functions in other libraries, and the linker is responsible for linking to and linking the functions we need. An ELF file will contain required segments, such as .text, .data, and some custom segments, and the linker will put the corresponding segments together according to the link script (if any). After the above four steps, a program can be run.
Corresponding command: gcc-L
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
# include # include int main (int argc,char * argv []) {int serv_sock
© 2024 shulou.com SLNews company. All rights reserved.