In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-12 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "the method of compiling C language program environment". In the daily operation, I believe that many people have doubts about the method of compiling C language program environment. The editor has consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "the method of compiling C language program environment". Next, please follow the editor to study!
I. the translation environment of the program (compilation and linking)
In any implementation of ANSI C, there are two different environments:
The first is the translation environment, where the source code is converted into executable machine instructions.
The second is the execution environment, which is used to actually execute code.
As shown below: this is the approximate process of our compiler compiling a source file to an executable file.
Each source file (test.c) that makes up a program is converted into object code (test.obj) through the compilation process.
Each object file is bundled together by a linker to form a single and complete executable program.
The linker also introduces any functions used by the program in the standard c function library.
Turning a source file (test.c) into a final binary file (test.exe) can be simply represented by the following figure:
Looking at the picture above, we know that compilation is divided into three steps:
Pre-compilation (preprocessing) (test.c-> test.i)
(1) process all comments and replace them with spaces
(2) delete all # define and expand all macro definitions
(3) processing conditional compilation instructions # if, # ifdef, # elif, # else, # endif
(4) deal with # include and expand the included file
(5) retain the # pragma instructions that the compiler needs to use
Compile (test.i-> test.s)
(1) compile the C language code into assembly code
(2) carry on syntax analysis, lexical analysis, semantic analysis, symbol summary to form symbol table.
Compilation (test.s-> test.o)
The assembly process actually refers to the process of translating assembly language code into target machine instructions. For each C language source program processed by the translation system, the corresponding object file will be finally obtained through this processing. What is stored in the object file is the machine language code of the target equivalent to the source program.
When the link is executed after compilation, what will the link do?
Merge segment table
Merging and relocation of symbol tables
Final formation (test.exe)
Second, the running environment of the program
The program must be loaded into memory, in an operating system environment: usually this is done by the operating system. In a separate environment, the loading of the program must be arranged manually, or it may be done by placing the executable code into read-only memory.
The execution of the program begins, and then the main function is called.
Start executing the program code, when the program uses a runtime stack to store local variables and return addresses of functions, and the program also uses static memory, where variables in static memory retain their values throughout the program's execution.
Terminate the program. Terminate the main function normally or unexpectedly (code error)
At this point, the study of "the method of compiling C language program environment" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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
© 2024 shulou.com SLNews company. All rights reserved.