下面是target_link_libraries中的解释,不想看英文的,直接拉到最后。 Link Inheritance Similarly, for anytarget, in the linking stage, we would need to decide, given theitemto be linked, whether we have to put theitemin the link dependencies, or the link interface, or both, in the compiledtarg...
所以,使用PRIVATE PUBLIC和INTERFACE就能控制是否将当前搜索路径传递给下一个目标。 PRIVATE就是不把当前的INCLUDE_DIRECTORIES 传递给INTERFACE_INCLUDE_DIRECTORIES 。 PUBLIC就是把当前的INCLUDE_DIRECTORIES 传递给INTERFACE_INCLUDE_DIRECTORIES 。 INTERFACE就是自己不使用当前的INCLUDE_DIRECTORIES ,但是把当前的INCLUDE_DIRECT...
PRIVATE 在private后面的库仅被link到你的target中,并且终结掉,第三方不能感知你调了啥库 INTERFACE 在interface后面引入的库不会被链接到你的target中,只会导出符号。 --- 更新--- target_link_libraries 会在目标程序中生成rpath, 这点请注意 。
CMake target_link_libraries Interface Dependencies - Stack Overflow CMake的链接选项:PRIVATE,INTERFACE,PUBLIC - 知乎 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...
PUBLIC:公开的。PUBLIC = PRIVATE + INTERFACE。生成 libhello-world.so 时,在 hello_world.c 和 hello_world.h 中都包含了 hello.h。并且 main.c 中也需要使用 libhello.so 提供的功能。那么在 hello-world/CMakeLists.txt 中应该写入: target_link_libraries(hello-world PUBLIC hello) ...
target_link_libraries(bar PUBLIC foo)链接为public,main函数正常调用foo(),bar中正常调用foo(),库foo链接给bar,同时foo也被传给了main。 target_link_libraries(bar PRIVATE foo)编译,发现main.cpp: undefined reference to `foo()',main.cpp这个编译单元找不到foo()这个符号,库foo链接到bar就被终结了,bar自...
CMake target_link_libraries Interface Dependencies http://stackoverflow.com/questions/26037954/cmake-target-link-libraries-interface-dependencies 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...
link_libraries(my_app PUBLIC my_public_lib PRIVATE my_private_lib) # 链接一个INTERFACE库,...
[<INTERFACE|PUBLIC|PRIVATE> [items2...] ...]) <target>必须是已经通过add_executable()或add_library()等命令创建出来的目标,对于每一个添加的目录,也有可选的范围参数PUBLIC、PRIVATE和INTERFACE,区别是:指定PUBLIC或PRIVATE时,目录会添加到目标的LINK_DIRECTORIES属性中;指定PUBLIC或INTERFACE时,目录会添加到目标...
target_link_libraries(<target><PRIVATE|PUBLIC|INTERFACE> <item>...[<PRIVATE|PUBLIC|INTERFACE> <item>...]...) PUBLIC、PRIVATE 和 INTERFACE 范围关键字可用于在一个命令中指定链接依赖关系和链接接口。 紧跟在 PUBLIC 后的库和目标将被链接,并成为链接接口的一部分。紧跟在 PRIVATE ...