[CMake] target_link_libraries is using relative path of library

Andreas Naumann Andreas-Naumann at gmx.net
Sun Jan 8 08:35:26 EST 2017


Hello,

on Linux cmake treats system directorys specially, i.e. those libraries 
are linked without any path.
Furthermore there are environment variables, whose content is added to 
the set of system directories.
I do not work on Windows, but your problem looks like a smiliar problem. 
Does some of the environment variables (except path) contain your 
directory?

Hope that helps,
Andreas

Am 08.01.2017 um 04:01 schrieb Saad Khattak:
> Hello,
>
> This is a very strange behavior I am encountering. I am using CMake 
> 3.7.1 with Visual Studio 2015. I have the following as part of a 
> CMakeLists file:
>
> find_library(glfw_LIB_D  glfw3_d ${glfw_LIBRARIES})
> find_library(glfw_LIB    glfw3   ${glfw_LIBRARIES})
>
> When I do "message(STATUS ${glfw_LIB_D})" I get the full absolute 
> path. However, when I add an executable that depends on the library:
>
> add_executable(vk_test  src/vulkan_test.cpp  )
> target_link_libraries(vk_test ${glfw_LIB_D})
>
> CMake puts the relative path when I look at my project's project 
> properties:
>
> ..\install\glfw\lib\glfw_d.lib
>
> I also tried the following:
>
> target_link_libraries(vk_test 
> "${CMAKE_SOURCE_DIR}/install/glfw/lib/glfw_d.lib")
>
> And it's still a relative path. Because of this issue, my project will 
> not compile as Visual Studio is looking for the library in the 
> incorrect folder.
>
> I even set the following, thinking that somehow relative paths got set:
>
> set(${CMAKE_USE_RELATIVE_PATHS} FALSE FORCE)
>
> I still got the same relative path. What is going on?
>
>



More information about the CMake mailing list