I set the CFLAGS in CMake by CMAKE_C_FLAGS. Is something like this to set LDFLAGS?
相关问题
- Error building gcc 4.8.3 from source: libstdc++.so
- What are the recommended GNU linker options to spe
- What is the right order of linker flags in gcc?
- Avoid cmake to add the flags -search_paths_first a
- CMakeList file to generate LLVM bitcode file from
相关文章
- gcc/g++ gives me error “CreateProcess: No such fil
- Calls that precede a function's definition can
- How can I use gcc's -I command to add recursiv
- How do I know if std::map insert succeeded or fail
- How to specify gcc flags (CXXFLAGS) particularly f
- How to generate assembly code with gcc that can be
- Embedding a program's source code into its bin
- What is the purpose of “-Wa,option” in GCC? [close
Look at:
If you want to add a flag to every link, e.g.
-fsanitize=address
then I would not recommend usingCMAKE_*_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 uselink_libraries()
:This works for everything.
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:
For linking against libraries see Andre's answer.
For linker flags - the following 4 CMake variables:
can be easily manipulated for different configs (debug, release...) with the ucm_add_linker_flags macro of ucm
You can specify linker flags in target_link_libraries.