1

I’m using Linux Mint 20.1. I have installed freeglut3 and freeglut3-dev and I’m trying to compile code which uses freeglut. I’m compiling like this:

g++ -lGL -lGLU -lglut main.cpp -o out

I’m including freeglut at the beginning of main.cpp and it looks like this:

#include <GL/freeglut.h>
#include <GL/glut.h>

And the compilation errors I’m getting look like this:

/usr/bin/ld: /tmp/ccT1q55n.o: in function `resize(int, int)':
main.cpp:(.text+0x3a): undefined reference to `glViewport'
/usr/bin/ld: main.cpp:(.text+0x44): undefined reference to `glMatrixMode'
/usr/bin/ld: main.cpp:(.text+0x49): undefined reference to `glLoadIdentity'
/usr/bin/ld: main.cpp:(.text+0x113): undefined reference to `glOrtho'
/usr/bin/ld: main.cpp:(.text+0x1c4): undefined reference to `glOrtho'
/usr/bin/ld: main.cpp:(.text+0x238): undefined reference to `glOrtho'
/usr/bin/ld: main.cpp:(.text+0x2f7): undefined reference to `glFrustum'
/usr/bin/ld: main.cpp:(.text+0x39d): undefined reference to `glFrustum'
/usr/bin/ld: main.cpp:(.text+0x406): undefined reference to `glFrustum'
/usr/bin/ld: main.cpp:(.text+0x46a): undefined reference to `gluPerspective'
/usr/bin/ld: main.cpp:(.text+0x474): undefined reference to `glMatrixMode'
/usr/bin/ld: main.cpp:(.text+0x479): undefined reference to `glLoadIdentity'
/usr/bin/ld: /tmp/ccT1q55n.o: in function `display()':
main.cpp:(.text+0x492): undefined reference to `glutGet'
/usr/bin/ld: main.cpp:(.text+0x4c7): undefined reference to `glClear'
/usr/bin/ld: main.cpp:(.text+0x4e0): undefined reference to `glColor3d'
/usr/bin/ld: main.cpp:(.text+0x4e5): undefined reference to `glPushMatrix'
/usr/bin/ld: main.cpp:(.text+0x51e): undefined reference to `glTranslated'
/usr/bin/ld: main.cpp:(.text+0x553): undefined reference to `glRotated'
/usr/bin/ld: main.cpp:(.text+0x588): undefined reference to `glRotated'
/usr/bin/ld: main.cpp:(.text+0x592): undefined reference to `glBegin'
/usr/bin/ld: main.cpp:(.text+0x5a3): undefined reference to `glVertex3d'
/usr/bin/ld: main.cpp:(.text+0x5bc): undefined reference to `glVertex3d'
/usr/bin/ld: main.cpp:(.text+0x5cd): undefined reference to `glVertex3d'
/usr/bin/ld: main.cpp:(.text+0x5e6): undefined reference to `glVertex3d'
/usr/bin/ld: main.cpp:(.text+0x5f7): undefined reference to `glVertex3d'
/usr/bin/ld: /tmp/ccT1q55n.o:main.cpp:(.text+0x610): more undefined references to `glVertex3d' follow
/usr/bin/ld: /tmp/ccT1q55n.o: in function `display()':
main.cpp:(.text+0x84f): undefined reference to `glEnd'
/usr/bin/ld: main.cpp:(.text+0x854): undefined reference to `glPopMatrix'
/usr/bin/ld: main.cpp:(.text+0x859): undefined reference to `glutSwapBuffers'
/usr/bin/ld: /tmp/ccT1q55n.o: in function `key(unsigned char, int, int)':
main.cpp:(.text+0x9cd): undefined reference to `glutPostRedisplay'
/usr/bin/ld: /tmp/ccT1q55n.o: in function `Menu(int)':
main.cpp:(.text+0xa2c): undefined reference to `glutGet'
/usr/bin/ld: main.cpp:(.text+0xa38): undefined reference to `glutGet'
/usr/bin/ld: main.cpp:(.text+0xa5a): undefined reference to `glutGet'
/usr/bin/ld: main.cpp:(.text+0xa66): undefined reference to `glutGet'
/usr/bin/ld: main.cpp:(.text+0xa88): undefined reference to `glutGet'
/usr/bin/ld: /tmp/ccT1q55n.o:main.cpp:(.text+0xa94): more undefined references to `glutGet' follow
/usr/bin/ld: /tmp/ccT1q55n.o: in function `idle()':
main.cpp:(.text+0xb09): undefined reference to `glutPostRedisplay'
/usr/bin/ld: /tmp/ccT1q55n.o: in function `main':
main.cpp:(.text+0xb32): undefined reference to `glutInit'
/usr/bin/ld: main.cpp:(.text+0xb41): undefined reference to `glutInitWindowSize'
/usr/bin/ld: main.cpp:(.text+0xb50): undefined reference to `glutInitWindowPosition'
/usr/bin/ld: main.cpp:(.text+0xb5a): undefined reference to `glutInitDisplayMode'
/usr/bin/ld: main.cpp:(.text+0xb66): undefined reference to `glutCreateWindow'
/usr/bin/ld: main.cpp:(.text+0xb72): undefined reference to `glutReshapeFunc'
/usr/bin/ld: main.cpp:(.text+0xb7e): undefined reference to `glutDisplayFunc'
/usr/bin/ld: main.cpp:(.text+0xb8a): undefined reference to `glutKeyboardFunc'
/usr/bin/ld: main.cpp:(.text+0xb96): undefined reference to `glutIdleFunc'
/usr/bin/ld: main.cpp:(.text+0xba2): undefined reference to `glutCreateMenu'
/usr/bin/ld: main.cpp:(.text+0xbb3): undefined reference to `glutAddMenuEntry'
/usr/bin/ld: main.cpp:(.text+0xbc4): undefined reference to `glutAddMenuEntry'
/usr/bin/ld: main.cpp:(.text+0xbd5): undefined reference to `glutAddMenuEntry'
/usr/bin/ld: main.cpp:(.text+0xbe6): undefined reference to `glutAddMenuEntry'
/usr/bin/ld: main.cpp:(.text+0xbf7): undefined reference to `glutAddMenuEntry'
/usr/bin/ld: /tmp/ccT1q55n.o:main.cpp:(.text+0xc08): more undefined references to `glutAddMenuEntry' follow
/usr/bin/ld: /tmp/ccT1q55n.o: in function `main':
main.cpp:(.text+0xc12): undefined reference to `glutAttachMenu'
/usr/bin/ld: main.cpp:(.text+0xc37): undefined reference to `glClearColor'
/usr/bin/ld: main.cpp:(.text+0xc41): undefined reference to `glEnable'
/usr/bin/ld: main.cpp:(.text+0xc4b): undefined reference to `glCullFace'
/usr/bin/ld: main.cpp:(.text+0xc55): undefined reference to `glEnable'
/usr/bin/ld: main.cpp:(.text+0xc5f): undefined reference to `glDepthFunc'
/usr/bin/ld: main.cpp:(.text+0xc69): undefined reference to `glEnable'
/usr/bin/ld: main.cpp:(.text+0xc73): undefined reference to `glEnable'
/usr/bin/ld: main.cpp:(.text+0xc7d): undefined reference to `glEnable'
/usr/bin/ld: main.cpp:(.text+0xc87): undefined reference to `glEnable'
/usr/bin/ld: main.cpp:(.text+0xc9d): undefined reference to `glLightfv'
/usr/bin/ld: main.cpp:(.text+0xcb3): undefined reference to `glLightfv'
/usr/bin/ld: main.cpp:(.text+0xcc9): undefined reference to `glLightfv'
/usr/bin/ld: main.cpp:(.text+0xcdf): undefined reference to `glLightfv'
/usr/bin/ld: main.cpp:(.text+0xcf5): undefined reference to `glMaterialfv'
/usr/bin/ld: main.cpp:(.text+0xd0b): undefined reference to `glMaterialfv'
/usr/bin/ld: main.cpp:(.text+0xd21): undefined reference to `glMaterialfv'
/usr/bin/ld: main.cpp:(.text+0xd37): undefined reference to `glMaterialfv'
/usr/bin/ld: main.cpp:(.text+0xd3c): undefined reference to `glutMainLoop'
collect2: error: ld returned 1 exit status

So basically everything is undefined as if I were missing something. What am I doing wrong? I’ve searched on the internet but there doesn’t seem to be anything I’m doing wrong (but it’s also hard to find a clear guide on this). I tried different -l options like -lfreeglut but g++ rejects them (/usr/bin/ld: cannot find -lfreeglut).

It used to work on my previous distro (Fedora) but that was a while ago and I might’ve forgotten to add something. I feel like it’s some stupid detail I forgot.

  • 2
    Try changing the order of the command line to `g++ main.cpp -lGLU -lglut -lGL -o out` . Linking is one pass left to right (without other linker options). So until it got to `main.cpp` there were no missing externals and the libraries before were effectively ignored. (I have over-simplified this a bit) – Richard Critten May 19 '22 at 13:41
  • @RichardCritten This was it, thanks a lot! I knew it was something dumb like this. – MichaelTheSlav May 19 '22 at 13:48

0 Answers0