当前位置:网站首页>Add of cmake_ dependencies
Add of cmake_ dependencies
2022-07-24 01:23:00 【Little ash of the prairie】
brief introduction
add_dependencies(<target> [<target-dependency>]...)
- Official documents explain this as : Add dependencies between top-level goals . Make top layer target Rely on other top-level goals , To make sure they're in target Before building . The top goal is made up of add_executable(),add_library() or add_custom_target() Created by one of the commands .
example
Directory structure
├── CMakeLists.txt
├── lib
│ ├── CMakeLists.txt
│ ├── mymath.cpp
│ └── mymath.h
└── src
├── CMakeLists.txt
└── main.cpp
Outermost layer cmake
# Appoint cmake Minimum version
cmake_minimum_required(VERSION 3.14)
# Specify project name
project(demo)
# Add subdirectories
add_subdirectory(${PROJECT_SOURCE_DIR}/src)
add_subdirectory(${PROJECT_SOURCE_DIR}/lib)
lib Under the table of contents cmake
# Appoint cmake Minimum version
cmake_minimum_required(VERSION 3.14)
// Specify the library file generation directory
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
// Generate library files
add_library(myMath SHARED ${PROJECT_SOURCE_DIR}/lib/mymath.cpp)
src Under the table of contents cmake
# Appoint cmake Minimum version
cmake_minimum_required(VERSION 3.14)
# Specify the location of the header file
include_directories(${PROJECT_SOURCE_DIR}/lib)
# Set the executable file generation directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
# Generate executable files
add_executable(res ${PROJECT_SOURCE_DIR}/src/main.cpp)
# Link dynamic library
target_link_libraries(res ${PROJECT_BINARY_DIR}/bin/libmyMath.so)
test
- We compile the code directly
[[email protected] build]# make
Scanning dependencies of target res
[ 25%] Building CXX object src/CMakeFiles/res.dir/main.cpp.o
make[2]: *** No rule to make target 'bin/libmyMath.so', needed by 'bin/res'. Stop.
make[1]: *** [CMakeFiles/Makefile2:91: src/CMakeFiles/res.dir/all] Error 2
make: *** [Makefile:84: all] Error 2
[[email protected] build]#
- You can see that there will be errors , Because when we add subdirectories on the outermost layer , To add src subdirectories , That is to say, we are generating executable files res when , When linking library files , The library file has not been generated . Of course, you can adjust the order of adding subdirectories , Sir, the library file , Regenerate into executable . But in real development , When linking library files , There are still many scenes in which the library file has not been generated .
- It can be used at this time add_dependencies command . modify src In the catalog cmake
# Appoint cmake Minimum version
cmake_minimum_required(VERSION 3.14)
# Specify the location of the header file
include_directories(${PROJECT_SOURCE_DIR}/lib)
# Set the executable file generation directory
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
# Generate executable files
add_executable(res ${PROJECT_SOURCE_DIR}/src/main.cpp)
# Designated dependency
add_dependencies(res myMath)
# Link dynamic library
target_link_libraries(res ${PROJECT_BINARY_DIR}/bin/libmyMath.so)
- add to add_dependencies(res myMath), It means to tell the compiler , I know generate res Program to link myMath This library file , But now I don't have this library file , Your husband Cheng res, I then put the library file myMath Generate it for you .
边栏推荐
- cmake之add_dependencies
- Group chat room based on UDP
- Description of TCP packet sticking problem code
- SCM learning notes 9 -- common communication methods (based on Baiwen STM32F103 series tutorials)
- General method of C language supporting yaml configuration file
- HCIP,OSPF综合实验
- HCIP第六天_特殊区域综合实验
- Under instruction
- Idea compiler sets the separation line between methods
- How safe is Volvo XC90? 5 seats and 7 seats are available
猜你喜欢

The flare project celery uses the pits encountered in redis sentinel

SCM learning notes 5--stm32 clock system (based on Baiwen STM32F103 series tutorials)

HCIA的复习

HCIP实验

Matlab提取论文插图中原始数据—Fig2Data工具

How safe is Volvo XC90? 5 seats and 7 seats are available

2022全球开发者薪资曝光:中国排第19名,平均年薪23,790美元

HCIP,OSPF综合实验

基于强化空间注意力的视网膜网络(ESA-Unet)

罗克韦尔AB PLC RSLogix5000中的位指令使用方法介绍
随机推荐
RPM build has installed the dependent package, but it still reports an error. There is no module provided in the package
Redis - basic concept
Bat Code: batch file underline rename
Arm architecture and programming 6 -- Relocation (based on Baiwen arm architecture and programming tutorial video)
HCIP第九天笔记
Arm architecture and programming 3 -- key control LED (based on Baiwen arm architecture and programming tutorial video)
High voltage technical examination questions with answers
Research on retinal vascular segmentation based on GAN using few samples
Explanation of terms in Polymer Physics
128. 最长连续序列
Idea setting automatic package import and useless package deletion
C language: explain in detail the two local communication methods based on TCP and UDP
LVS load balancing scheduling principle and configuration method
Form resume
面试了二三十家公司所总结的问题,Android面试吃完这一套没有拿不到的Offer......
为什么博途V17及以下的HMI面板不能与1500固件版本2.9或1200版本4.5 的CPU建立连接?
How safe is Volvo XC90? 5 seats and 7 seats are available
Deep understanding of collaborative process
小熊派简介和环境搭建
High voltage technology test questions and answers