如何在 CMakeLists.txt 中设置 LDFLAGS? [英] How to set the LDFLAGS in CMakeLists.txt?
问题描述
我通过 CMAKE_C_FLAGS 在 CMake 中设置了 CFLAGS.像这样设置 LDFLAGS 吗?
I set the CFLAGS in CMake by CMAKE_C_FLAGS. Is something like this to set LDFLAGS?
推荐答案
这取决于你想要什么:
A) 如果要指定链接到哪些库,可以使用 find_library 找到库,然后使用 link_directories 和 target_link_libraries一>到.
A) If you want to specify which libraries to link to, you can use find_library to find libs and then use link_directories and target_link_libraries to.
当然,写一个好的find_package 脚本,它很好地添加了带有 add_library( YourLib IMPORTED ) 具有正确的位置,以及平台/构建特定的前缀和后缀.然后,您可以简单地引用YourLib"并使用 target_link_libraries.
Of course, it is often worth the effort to write a good find_package script, which nicely adds "imported" libraries with add_library( YourLib IMPORTED ) with correct locations, and platform/build specific pre- and suffixes. You can then simply refer to 'YourLib' and use target_link_libraries.
B) 如果您希望指定特定的链接器标志,例如'-mthreads' 或 '-Wl,--export-all-symbols' 与 MinGW-GCC,你可以使用 CMAKE_EXE_LINKER_FLAGS.对于模块、共享库或静态库,还有两个类似但未记录的标志:
B) If you wish to specify particular linker-flags, e.g. '-mthreads' or '-Wl,--export-all-symbols' with MinGW-GCC, you can use CMAKE_EXE_LINKER_FLAGS. There are also two similar but undocumented flags for modules, shared or static libraries:
CMAKE_MODULE_LINKER_FLAGS
CMAKE_SHARED_LINKER_FLAGS
CMAKE_STATIC_LINKER_FLAGS
这篇关于如何在 CMakeLists.txt 中设置 LDFLAGS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!