如何在CMakeLists.txt中设置LDFLAGS? [英] How to set the LDFLAGS in CMakeLists.txt?

查看:1640
本文介绍了如何在CMakeLists.txt中设置LDFLAGS?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过CMAKE_C_FLAGS在CMake中设置了CFLAGS. 是这样设置LDFLAGS吗?

I set the CFLAGS in CMake by CMAKE_C_FLAGS. Is something like this to set LDFLAGS?

推荐答案

这取决于您想要的内容:

It depends a bit on what you want:

A)如果要指定要链接的库,则可以使用 find_library 查找库,然后使用链接目录 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.

当然,通常值得花很多精力来编写一个 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)如果您希望指定特定的链接器标志,例如与MinGW-GCC一起使用的'-mthreads'或'-Wl,-export-all-symbols',您可以使用

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆