How to set the LDFLAGS in CMakeLists.txt?

后端 未结 5 2277
小蘑菇
小蘑菇 2020-11-30 22:15

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

5条回答
  •  心在旅途
    2020-11-30 22:52

    If you want to add a flag to every link, e.g. -fsanitize=address then I would not recommend using CMAKE_*_LINKER_FLAGS. Even with them all set it still doesn't use the flag when linking a framework on OSX, and maybe in other situations. Instead use link_libraries():

    add_compile_options("-fsanitize=address")
    link_libraries("-fsanitize=address")
    

    This works for everything.

提交回复
热议问题