CMake:如何在CMakeLists.txt中设置LDFLAGS? [英] CMake: 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
这篇关于CMake:如何在CMakeLists.txt中设置LDFLAGS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!