Reputation: 81
I cannot link glm library with my executable. I tried link via
${GLM_INCLUDE_DIRS}
, ${GLM_LIBRARIES}
and ${GLM_LIBRARY_DIRS}
cmake variables but it does not work.
How can I link libraries and inludes of glm with my executable?
I am using find_package()
method :
find_package(glm REQUIRED PATHS "${GLM_BINARY_DIR}" NO_DEFAULT_PATH)
And does not have any problem with find_package()
but these status messages below displays nothing :
message(STATUS "GLM includes ${GLM_INCLUDE_DIRS}")
message(STATUS "GLM libraries ${GLM_LIBRARY_DIRS}")
Upvotes: 2
Views: 12589
Reputation: 21
Honestly for me, I am using MacOS and I found installing GLM from the github to work:
git clone https://github.com/g-truc/glm
Then I build and install it:
cd /path/to/glm
cmake \
-DGLM_BUILD_TESTS=OFF \
-DBUILD_SHARED_LIBS=OFF \
-B build .
cmake --build build -- all
cmake --build build -- install
This worked for me: https://github.com/g-truc/glm
Upvotes: 0
Reputation: 66089
Config script for GLM defines IMPORTED target glm::glm
.
So the correct way for use GLM in CMake code is to link with that target.
This is explicitly written in the documentation:
set(glm_DIR <installation prefix>/lib/cmake/glm) # if necessary
find_package(glm REQUIRED)
target_link_libraries(<your executable> glm::glm)
Variables like GLM_LIBRARIES
or GLM_INCLUDE_DIRS
are usually defined by Find scripts (shipped with CMake or with the consumer project).
Config scripts, shipped with the installed package, normally defines IMPORTED targets.
GLM doesn't have a Find script (see FindGLM.cmake not in glm 0.9.7, is it a deprecated way to find libraries in CMAKE?), and PATHS
option in find_package
invocation explicitly requests Config script.
Upvotes: 8
Reputation: 81
My approach was wrong.
From OpenGL GLM offical page:
OpenGL Mathematics (GLM) is a header only C++ mathematics library for graphics software based on the OpenGL Shading Language (GLSL) specifications.
So, I just need to specify the /include
path of builded GLM library in which the linker should search for libraries when linking a given target.
That can be handled by cmake target_include_directories()
function. This fixed my problem :
target_include_directories(myExecutable "${GLM_BINARY_DIR}/include")
${GLM_BINARY_DIR}
is defined by me and points to the where GLM binaries are stored.
Upvotes: -1