Why does cmake_link_libraries include static libraries?

I want my executable to link the shared library again (libmy_so.so), which in turn is built with the static library (libmy_static_lib.a). When i do

target_link_libraries(my_exe my_so) 

I see at compilation that cmake added libmy_static_lib.a in the assembly line. This is not what I want, and I do not understand why this is necessary. Is there any way around this? LINK_PRIVATE does not seem to make any difference.

I am using CMake 2.8.9.

+5
source share
1 answer

From the CMake Documentation for target_link_libraries :

 target_link_libraries(<target> [item1 [item2 [...]]] [[debug|optimized|general] <item>] ...) 

[...] Library dependencies are in transit by default with this signature. When this goal is linked to another goal, libraries associated with that goal will also appear on the link line for another goal.

The solution is to use the signature target_link_libraries , which allows you to manually specify transitive behavior:

 # we explicitly state that the static lib should not propagate # transitively to targets depending on my_so target_link_libraries(my_so PRIVATE my_static_lib) # nothing has to change for the exe target_link_libraries(my_exe my_so) 
+5
source

All Articles