Issue
Both static and shared versions of a specific library are in the same folder, then which library does Cmake
prefer to link to when invoking target_link_libraries(target_name, library_name_without_postfix)
?
Why?
Solution
If target_link_libraries takes the library name in the 2nd parameter, it entirely depends on the linker. In your case, the link line will be translated to
-llibrary_name_without_postfix.
In this case, it will be searched in the standard path like, LD_LIBRARY_PATH, /etc/ld.so.conf or in the system path.
Since you didn't say anything about the location, I assume the library lives in the current build directory. And you have a command somewhere including the current build directory in the linker path using link_directories
. In this case, the default link is dynamic.
Answered By - asitdhal