I’ve been trying to use some GLM extensions (GTX) in my source code without success. They fail when gcc tries to link them.
I created a test code that does nothing. I just wanted to test if I’d be able to include extensions.
The code is the following:
#include <glm/glm.hpp>
#include <glm/gtx/closest_point.hpp>
int foo()
{
glm::vec3 p1(0,0,0) , p2(0,1,0), p3(0,0,1);
glm::closestPointOnLine(p1,p2,p3);
return 0;
}
int main() {
return foo();
}
I’m able to generate the object file with gcc, but when I try to generate the executable the following error is returned:
teste.cpp:(.text+0xa3): undefined reference to `glm::detail::tvec3<float> glm::gtx::closest_point::closestPointOnLine<float>(glm::detail::tvec3<float> const&, glm::detail::tvec3<float> const&, glm::detail::tvec3<float> const&)'
GLM is supposed to be header-only, so it can’t be a missing library problem when compiling.
I tried to take a look at “/usr/include/glm/gtx/closest_point.hpp”, and I noticed that the method is actually implemented in “/usr/include/glm/gtx/closest_point.inl”. The HPP file includes the INL, however there was something there that did not seem to make sense to me.
Both files contain the following definition on top of them:
#ifndef glm_gtx_closest_point
#define glm_gtx_closest_point
It does not seem that the implementation will ever be actually included.