[CMake] How to override CMAKE_C_IMPLICIT_LINK_LIBRARIES

Nils Gladitz nilsgladitz at gmail.com
Tue Jan 26 02:46:08 EST 2016


On 01/26/2016 06:35 AM, 陆秋文 wrote:
> I have the need to link a shared library to all the targets without 
> modifying the CMakeLists.txt(for example, tcmalloc.so). I used the 
> command:
>
> # cmake -DCMAKE_C_IMPLICIT_LINK_LIBRARIES:STRING=tcmalloc
>
> However, It didn't work. I used the message() command to print the 
> CMAKE_C_IMPLICIT_LINK_LIBRARIES, It show:
>
> -- CMAKE_C_IMPLICIT_LINK_LIBRARIES=c
>
> Can someone point me why this happens? Thanks very much!

Implicit link libraries are those that the compiler (not CMake) itself 
implicitly links.
They are detected by CMake and stored in the variable; the variable is 
not meant to be modified.

I can't think of any way to portably link libraries without modifying 
the project.
(There are linker flag variables e.g. CMAKE_EXE_LINKER_FLAGS but they 
are inserted before object files on the command line which will not work 
for many toolsets)

link_libraries() [1] might have the smallest impact if you do end up 
having to modify the project.

Nils

[1] https://cmake.org/cmake/help/v3.4/command/link_libraries.html


More information about the CMake mailing list