[英]In CMake, specify all executables target_link_libraries certain libraries
[英]CMake target_link_libraries not preserving order
我正在使用CMake 3.8.2(随JetBrains CLion一起提供)并链接自定义项目的几个静态库。
由于我需要保留静态符号(遗留),我将自己的程序部分包含在target_link_libraries(${TARGET} -Wl,--whole-archive ${MY_LIBRARY} -Wl,--no-whole-archive)
。
这在大多数情况下都有效,但在某些时候,链接器命令将是这样的:
/usr/bin/c++ -g CMakeFiles/my_exe.dir/my_exe.cpp.o -o my_exe libmy_other_lib.a -Wl,--whole-archive -Wl,--no-whole-archive
这是无用的,因为事先添加了库,然后发生-Wl,--whole-archive -Wl,--no-whole-archive
。
请注意,我需要在链接my_other_lib.a之后添加类似-Wl,--no-whole-archive
,因为我不想将此选项用于外部依赖项。
对此有何看法?
尝试将这些标志作为单个参数传递给target_link_libraries
,而不是作为列表:
target_link_libraries(${TARGET} "-Wl,--whole-archive ${MY_LIBRARY} -Wl,--no-whole-archive")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.