target_link_libraries is using relative path of library

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

target_link_libraries is using relative path of library

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?

--

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
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: target_link_libraries is using relative path of library

Andreas Naumann
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?
>
>

--

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
Loading...