Search code examples
c++openglubuntucompilationglut

undefined reference to glutInit in program that compiled with the same commands just 2 weeks ago


My ubuntu installation recently died and I'm now reconstruction everything.

I have a file that I know recently compiled and worked with the same comment. This is a simple opengl-glut based program.

It compiles with the following line :

g++ -lGL -lGLU -lglut -I . *.cp

this gives the following error code:

main.cpp:(.text+0x2de): undefined reference to `glGetDoublev'
/tmp/cc9vO929.o: In function `tbVisuTransform()':
main.cpp:(.text+0x2fd): undefined reference to `glMultMatrixd'
/tmp/cc9vO929.o: In function `tbMotionFunc(int, int)':
main.cpp:(.text+0x4f5): undefined reference to `glLoadIdentity'
main.cpp:(.text+0x523): undefined reference to `glRotatef'
main.cpp:(.text+0x52d): undefined reference to `glMultMatrixd'
main.cpp:(.text+0x53c): undefined reference to `glGetDoublev'
main.cpp:(.text+0x649): undefined reference to `glLoadIdentity'
main.cpp:(.text+0x665): undefined reference to `glRotatef'
main.cpp:(.text+0x66f): undefined reference to `glMultMatrixd'
main.cpp:(.text+0x67e): undefined reference to `glGetDoublev'
main.cpp:(.text+0x724): undefined reference to `glutPostRedisplay'
/tmp/cc9vO929.o: In function `tbRotate(double, double, double, double)':
main.cpp:(.text+0x78c): undefined reference to `glLoadIdentity'
main.cpp:(.text+0x7b5): undefined reference to `glRotatef'
main.cpp:(.text+0x7bf): undefined reference to `glMultMatrixd'
main.cpp:(.text+0x7ce): undefined reference to `glGetDoublev'

this goes on for quite a while. I have already installed the build essential and freeglut. sudo apt-get install build-essential sudo apt-get install freeglut3 freeglut3-dev

anybody got any ideas?

I already tried what they said here: Error with GLUT compile in ubuntu

Note that I upgraded from ubuntu 12.04 to 14.04 if that matters.


Solution

  • Based on this and this links, Ubuntu has changed the default linking strategy in Oneiric (Ubuntu 11.10).

    As Oneiric and later versions use the --as-needed flag by default, the order of the libraries does matter in Ubuntu.