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添加链接选项
Gcc链接选项_jiang010的博客-CSDN博客_gcc 链接选项
版权归原作者 物随心转 所有, 如有侵权,请联系我们删除。