Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set the LDFLAGS in CMakeLists.txt?

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

like image 789
hich9n Avatar asked May 20 '11 20:05

hich9n


People also ask

What is Ldflags?

ldflags , then, stands for linker flags. It is called this because it passes a flag to the underlying Go toolchain linker, cmd/link , that allows you to change the values of imported packages at build time from the command line.

Where can I find CMakeLists txt?

CMakeLists. txt is placed at the root of the source tree of any application, library it will work for. If there are multiple modules, and each module can be compiled and built separately, CMakeLists. txt can be inserted into the sub folder.

What is Cmake_shared_linker_flags?

CMAKE_SHARED_LINKER_FLAGS. Linker flags to be used to create shared libraries. These flags will be used by the linker when creating a shared library.


2 Answers

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 
like image 78
André Avatar answered Sep 22 '22 13:09

André


Look at:

CMAKE_EXE_LINKER_FLAGS CMAKE_MODULE_LINKER_FLAGS CMAKE_SHARED_LINKER_FLAGS CMAKE_STATIC_LINKER_FLAGS 
like image 41
tibur Avatar answered Sep 22 '22 13:09

tibur