CMake指定目标的链接选项,有三种方案
方案一
通过target_link_options来设置,(version 3.13.以上)
add_executable(mymathApp mymathApp.cc)target_link_options(mymathApp PRIVATE -wl,-shared,-z,noexecstack)
方案二
通过目标的属性来设置
set_target_properties( PROPERTIES LINK_OPTIONS "-wl,-z,-relro" )
或者
set_target_properties( PROPERTIES LINK_FLAGS "-wl,-z,-relro" )
方案三
set(LINK_FLAGS)
## The options for the shared libraryset(LINK_FLAGS "-rdynamic -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now") ## the actual options for gccset(CMAKE_C_FLAGS "-fsigned-char ${COMPILE_FLAGS}")set(CMAKE_C_FLAGS_DEBUG "-g")set(CMAKE_C_FLAGS_RELEASE "-DNDEBUG") ## The linker optionsset(CMAKE_SHARED_LINKER_FLAGS "${LINK_FLAGS}")set(CMAKE_EXE_LINKER_FLAGS "${LINK_FLAGS}")
参考:
CMake 指定目标的链接选项_icbm的博客-CSDN博客_cmake添加链接选项
Gcc链接选项_jiang010的博客-CSDN博客_gcc 链接选项
来源地址:https://blog.csdn.net/sinat_31608641/article/details/128635869