In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
How to analyze the compilations and links in C++? aiming at this problem, this article introduces the corresponding analysis and answer in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
Foreword:
C++ has the biggest feature, that is, the compiled language. Compared with the interpretive language Python, C++ does a lot of processing at the compilation stage and has high efficiency at the execution stage. This article mainly explains the compilation and links in C++.
I. compiling and linking models
1. The initial C++ is a simple processing model, as shown in the following figure:
There are some problems with this:
Unable to handle large programs
Processing takes a long time
Even if there is a small amount of modification, it still needs to be reprocessed.
2. In order to solve the above problems, the method of block processing is introduced:
Benefits of compiling linked models:
Compilation consumes resources, but less input at a time
More links are input, but processing speed is fast
Easy to modify the program (only part of it needs to be modified)
With the introduction of blocking processing, some common concepts have emerged:
① definition and declaration: a variable only needs to be defined in one file, and other files can declare the variable by declaring it
② header file and source file: because too many variables and functions are declared, you can put the declaration in the header file and load these declarations by referencing the header file in the source file
③ translation unit: source file + related header file (direct / indirect)-preprocessing statements that should be ignored (macro definition does not meet the criteria)
II. Compilation and linking process
Here is a practical example to show how the program changes step by step from cpp to executable files.
The following figure shows an overall flow chart:
1. Pre-processing stage: the source program of cpp or c is processed (header file expansion, etc.) and converted into a translation unit file ending with I
Gmail +-E. / main.cpp-o. / main.i
2. Compilation phase: generate compiled assembly code files with the suffix s
Gmail + main.i-S-o main.s
3. Assembler phase: assemble the assembly code to generate the object file with o as suffix
4. Link phase: merge multiple object files, associate declarations and definitions, and generate executable programs
The above are the specific implementation operations within the system. In actual operation, we can use one-line command to realize the compilation link:
Gmail +. / main.cpp-o. / main
Note: when compiling a program with IDE, there are often two modes: Debug and Release,Debug are used in development with less optimization, and Release is used in the final program compilation with more optimization.
This is the answer to the question on how to analyze the compilations and links in C++. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.
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: 278
*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.