其实private/public 解决的是指示问题,本质上可以使用public 来解决, 可以减少坑。 下面是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 theitemi...
其实private/public 解决的是指示问题,本质上可以使用public 来解决, 可以减少坑。 下面是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 theitemi...
那么在 hello-world/CMakeLists.txt 中应该写入: target_link_libraries(hello-world INTERFACE hello) target_include_directories(hello-world INTERFACE hello) PUBLIC:公开的。PUBLIC = PRIVATE + INTERFACE。生成 libhello-world.so 时,在 hello_world.c 和 hello_world.h 中都包含了 hello.h。并且 main.c ...
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自...
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_include_direct...
链接库:使用 target_link_libraries 链接标志:使用 target_link_options 所谓可见性就是上述这些属性在不同target之间的传递性。有三种: PRIVATE PUBLIC INTERFACE 上面的这些都是很好理解。但INTERFACE是不好理解的。我们详细讲解。 INTERFACE 说到INTERFACE,我们先来看其他两种可见性:PUBLIC和PRIVATE。
另一个仅对其依赖目标可见target_link_libraries(my_app PUBLIC my_public_lib PRIVATE my_private_lib...
原文: CMake target_link_libraries Interface Dependencies http://stackoverflow.com/questions/26037954/cmake-target-link-libraries-interface-dependencies If you are creating a shared library ...
[<INTERFACE|PUBLIC|PRIVATE> [items2...] ...]) <target>必须是已经通过add_executable()或add_library()等命令创建出来的目标,对于每一个添加的目录,也有可选的范围参数PUBLIC、PRIVATE和INTERFACE,区别是:指定PUBLIC或PRIVATE时,目录会添加到目标的LINK_DIRECTORIES属性中;指定PUBLIC或INTERFACE时,目录会添加到目标...
target_link_libraries(<target><LINK_PRIVATE|LINK_PUBLIC> <lib>...[<LINK_PRIVATE|LINK_PUBLIC> <lib>...]...) LINK_PUBLIC 和 LINK_PRIVATE 模式可用于在一个命令中指定链接依赖关系和链接接口。 此签名仅用于兼容性。请改用 PUBLIC 或 PRIVATE 关键字。