CMake指定目标的链接选项,有三种方案
方案一
通过target_link_options来设置,(version 3.13.以上)
add_executable(mymathApp mymathApp.cc)
target_link_options(mymathApp PRIVATE -wl,-shared,-z,noexecstack)
方案二
通过目标的属性来设置
set_target_properties(<executable_name>
PROPERTIES
LINK_OPTIONS "-wl,-z,-relro"
)
或者
set_target_properties(<executable_name>
PROPERTIES
LINK_FLAGS "-wl,-z,-relro"
)
方案三
set(LINK_FLAGS)
## The options for the shared library
set(LINK_FLAGS "-rdynamic -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now")
## the actual options for gcc
set(CMAKE_C_FLAGS "-fsigned-char ${COMPILE_FLAGS}")
set(CMAKE_C_FLAGS_DEBUG "-g")
set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG")
## The linker options
set(CMAKE_SHARED_LINKER_FLAGS "${LINK_FLAGS}")
set(CMAKE_EXE_LINKER_FLAGS "${LINK_FLAGS}")
参考:
CMake教程系列-04-编译相关函数 - 知乎
CMake 指定目标的链接选项_icbm的博客-CSDN博客_cmake添加链接选项文章来源:https://www.toymoban.com/news/detail-622008.html
Gcc链接选项_jiang010的博客-CSDN博客_gcc 链接选项文章来源地址https://www.toymoban.com/news/detail-622008.html
到了这里,关于CMake 指定链接选项的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!