[CMake] How to use 'CMAKE_EXE_LINKER_FLAGS' correctly
Chaos Zhang
zcsd2012 at gmail.com
Mon May 23 02:23:59 EDT 2016
Thanks a lot! `set(FOO_LIBRARY "-Wl,--whole-archive ${FOO_LIBRARY}
-Wl,--no-whole-archive")` worked when the content of ${FOO_LIBRARY} look
like `-Ldir -llib`, if just use lib name as the content of ${FOO_LIBRARY},
error while occur.
Chuck Atkins wrote
>> -rpath
>
>
> RPATHs are automatically added by CMake to executables so they can use
> libraries from the build tree.
>
>
>
>> -whole-archive
>>
>
> whole-archive is definitely trickier since you shouldn't be applying it to
> the entire executable but instead wrapping individual libraries with it.
> Conveniently, you can pass link options directly with
> target_link_libraries. So you could have:
>
> # Just an example, find_library calls should really be isolated to
> separate
> find modules
> find_library(FOO_LIBRARY foo)
> set(FOO_LIBRARY "-Wl,--whole-archive ${FOO_LIBRARY}
> -Wl,--no-whole-archive")
>
> add_executable(hello main.c)
> target_link_libraries(hello ${FOO_LIBRARY})
>
>
>>> set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -L . -lhello")
>>
>
> CMAKE_EXE_LINKER_FLAGS should work for other more general cases that
> aren't
> tied to specific libraries. The problem with your example is likely not
> using an absolute path for -L since the compilation is actually taking
> place in a nested work directory somewhere.
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake
--
View this message in context: http://cmake.3232098.n2.nabble.com/How-to-use-CMAKE-EXE-LINKER-FLAGS-correctly-tp7593495p7593518.html
Sent from the CMake mailing list archive at Nabble.com.
More information about the CMake
mailing list