How to set the LDFLAGS in CMakeLists.txt?

后端 未结 5 2270
小蘑菇
小蘑菇 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 23:08

    It depends a bit on what you want:

    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.

    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) 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
    

提交回复
热议问题