CMake target_link_libraries 接口依赖 [英] CMake target_link_libraries Interface Dependencies
问题描述
我是 CMake 的新手,对与 target_link_libraries()
.文档提到它们可用于在一个命令中指定链接依赖项和链接接口.
I am new to CMake and a bit confused with the PUBLIC, PRIVATE and INTERFACE keywords related to target_link_libraries()
. Documentation mentions that they can be used to specify both the link dependencies and the link interface in one command.
链接依赖和链接接口究竟是什么意思?
What does link dependencies and link interface actually mean?
推荐答案
如果您正在创建一个共享库并且您的源 cpp
文件 #include
另一个库的标题(例如,QtNetwork
),但是你的头文件不包含 QtNetwork
头,那么 QtNetwork
是一个 PRIVATE代码>依赖.
If you are creating a shared library and your source cpp
files #include
the headers of another library (Say, QtNetwork
for example), but your header files don't include QtNetwork
headers, then QtNetwork
is a PRIVATE
dependency.
如果您的源文件和头文件包含另一个库的头文件,那么它就是一个 PUBLIC
依赖项.
If your source files and your headers include the headers of another library, then it is a PUBLIC
dependency.
如果你的头文件而不是你的源文件包含另一个库的头文件,那么它是一个 INTERFACE
依赖.
If your header files other than your source files include the headers of another library, then it is an INTERFACE
dependency.
PUBLIC
和 INTERFACE
依赖项的其他构建属性被传播到使用库.http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html#transitive-usage-requirements
Other build properties of PUBLIC
and INTERFACE
dependencies are propagated to consuming libraries. http://www.cmake.org/cmake/help/v3.0/manual/cmake-buildsystem.7.html#transitive-usage-requirements
这篇关于CMake target_link_libraries 接口依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!