View Full Version : Problem including glm extensions

11-09-2012, 09:48 PM
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);

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.

11-09-2012, 10:15 PM
So, it seems that closest_point is the only extension I tried that does not work.
I'm including it in my code the following way.

#include <glm/gtx/closest_point.hpp>
#undef glm_gtx_closest_point
#include <glm/gtx/closest_point.inl>

Now it works, even though this is the wrong way to fix it. I downloaded libglm-dev from ubuntu repositories, version
I noticed this is no longer a problem in newer versions, as the include was fixed.
I hope they update the repositories. I hate using stupid hacks to make things work correctly.