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--
one。 Directory structure of the project
Analysis.
a. The project is divided into several different modules
1. The code for each module is managed by a folder-- the folder is made up of inc,src,makefille
two。 The external function declaration of each module is uniformly placed in common/inc-such as commom.h xxxfunc.h
b. The compilation environment that needs to be created
1. The coding folder cannot be changed at compile time
two。 Automatically create a folder at compile time to hold the compilation results
3. In the process of compilation, dependencies can be generated automatically and files needed can be searched automatically.
4. Each module can have its own independent compilation mode.
5. Compile options that support debug versions
c. Design of the solution
Phase 1: compile the code in each module into a static file
Phase 2: link the static file of each module into a final executable program
two。 Realize
The first stage:
1. Complete the makefile file that can be used for compilation of each module
two。 The compilation result of each module is a static library file (.a file).
Key implementation points:
1. Automatically generate dependencies (gcc-MM)
two。 Automatically search for required files (vpath)
3. Package the target file as a static library file (ar crs)
Compiler implementation
Corresponding to the directory structure of the project, the corresponding folder contains the corresponding header files and source files
The result of the operation is shown in the figure.
Create a new makefile under the module folder and main folder, copy the current makefile, create an empty folder for module and main in build, run the make all command to generate .o files, and realize the makefile files compiled by each module.
The second phase of tasks:
1. Complete compilation of the makefile file of the whole project
two。 Call the module makefile to compile and generate static library files
3. Link the static library files of all modules and finally get the executable program.
Key implementation points
1. How to create build folders and subfolders
two。 How to enter each module folder to compile
3. How to link all module static libraries after successful compilation
Solution design
1. Define variable save module name list
two。 Traversing module name variables using for loop in Shell
3. Compile in the for loop by entering the module folder
4. Link all module static library files at the end of the loop
Considerations for links
A.gcc must follow strict dependencies when making static library links.
1.gcc-o app.out x.a y.a z.a "=" where the dependency must be: X.a-> y.a.a-> z.a; by default it follows a left-to-right dependency.
two。 If you are not aware of the dependencies between libraries, you can use-Xlinker to determine the dependencies automatically
Gcc-o app.out-Xlinker (x.ay.a z.a-Xlinker)
The running code and the running result are shown in the figure
In makefile, you can know that you can carry out make step by step or complete makefile step by step.
Result comparison chart
three。 Possible problems
a. The compilation paths used in all modules makefile are absolute paths written to death. Once the project folder is moved, the compilation will fail.
Solution:
1. Get the source path of the project in the project makefile
two。 According to the project source path: a: stitching to get the compiled file path (DIR_BUILD), b: stitching to get the global inclusion path (DIR_COMMON_INC)
3. Pass the path to the module makefile by defining a command line variable
Implementation of the code:
Where to move the previous code (marked with a red line)
Results of operation
Delete every absolute path in each makefile by modifying the makefile of each folder and find that the result of the run has not changed.
# #
b. The content of all modules makefile is exactly the same.
When the module makefile needs this action, multiple identical changes will be involved
Solution:
1. Split the module makefile into two template files
Mod-cfg.mk defines variables that may change
Mod-rule.mk defines relatively stable variables and rules
two。 By default
Module makefile reuse template file implementation function (include)
Key questions:
1. How does the module makefile know the specific location of the template file
two。 Solution: pass the location of the template file through the command line variable
Achieve:
. The running result is shown in the figure:
Four: summary
1. The compilation environment of large projects is made up of different makefile.
two。 The design of the compilation environment needs to be based on the overall framework of the project.
3. The compilation process of the whole project can be broken down into different phases.
4. Targeted design of makefile according to different stages
5.makefile also needs to consider basic program features such as reusability and maintainability.
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.