当前位置:网站首页>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
- Description of TCP packet sticking problem code
- OSI、TCP/IP(A1)
- Use of crawler request library 2
- RPM build has installed the dependent package, but it still reports an error. There is no module provided in the package
- Notes to Chapter 2 of kubernetes in action
- 面试题之:ArrayList和LinkedList有哪些区别
- Explanation and induction of polymer physics terms
- 出于数据安全考虑 荷兰教育部要求学校暂停使用Chrome浏览器
- cnpm 执行时卡住应该怎么解决?
猜你喜欢

SCM learning notes 9 -- common communication methods (based on Baiwen STM32F103 series tutorials)

kubernetes 部署 dashboard(可视化界面)

1000个Okaleido Tiger首发上线Binance NFT,引发抢购热潮

数字化转型时代的企业数据新基建 | 爱分析报告

The flare project celery uses the pits encountered in redis sentinel

Hypothesis test of Pearson correlation coefficient

Easyexcel export case (only you can't think of it)

数字签名技术简介

New infrastructure of enterprise data in the era of digital transformation | love Analysis Report

HCIP网络类型,ppp会话,数据链路层协议
随机推荐
Notes to Chapter 2 of kubernetes in action
Use and understanding of string functions (1)
Review questions of polymer synthesis technology
How to troubleshoot the problem that VPN server cannot forward
Hot 100 depth first
HCIP第九天笔记
【FreeSwitch开发实践】专栏简介
1000 okaleido tiger launched binance NFT, triggering a rush to buy
Bubble sort, quick sort
Use and understanding of string functions (2)
How safe is Volvo XC90? 5 seats and 7 seats are available
The problem that all values are the same occurs after golang for range traverses and assigns values to the dictionary
C language: student management system based on sequence table, super detailed, all with notes, if you don't understand it after reading, please slap me.
High voltage technology learning summary
[untitled]
Notes: binary tree pruning (recursion, iteration)
为什么博途V17及以下的HMI面板不能与1500固件版本2.9或1200版本4.5 的CPU建立连接?
128. 最长连续序列
数仓搭建——ODS层
Create.Img image file