1

I tried to install OpenGL libraries for ubuntu by following this tutorial -> http://kiwwito.com/installing-opengl-glut-libraries-in-ubuntu/ but when I try to run a program the example program I get this error message.

test2.c:(.text+0x1d): undefined reference to `glClearColor'
test2.c:(.text+0x27): undefined reference to `glClear'
test2.c:(.text+0x2c): undefined reference to `glFlush'
/tmp/ccNGbmFL.o: In function `main':
test2.c:(.text+0x50): undefined reference to `glutInit'
test2.c:(.text+0x5a): undefined reference to `glutInitDisplayMode'
test2.c:(.text+0x69): undefined reference to `glutInitWindowPosition'
test2.c:(.text+0x78): undefined reference to `glutInitWindowSize'
test2.c:(.text+0x82): undefined reference to `glutCreateWindow'
test2.c:(.text+0x8c): undefined reference to `glutDisplayFunc'
test2.c:(.text+0x91): undefined reference to `glutMainLoop'

When I remove those function and leave only #include <GL/glut.h> the program works fine. I have also tried this http://www.opengl-tutorial.org/beginners-tutorials/tutorial-1-opening-a-window/#Building_on_Linux installation guide but it doesn't work too. Also I have tried to install eclipse and add those libraries in C++ linker. Eclipse console output was:

16:02:45 **** Incremental Build of configuration Debug for project opengl_glut ****
make all 
Building file: ../main.cpp
Invoking: Cross G++ Compiler
g++ -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"main.d" -MT"main.d" -o "main.o" "../main.cpp"
Finished building: ../main.cpp

Building target: opengl_glut
Invoking: Cross G++ Linker
g++  -o "opengl_glut"  ./main.o   -lglut -lGL -lm -lXrandr -lXi -lX11 -lXxf86vm -lpthread -lglfw3 -lGLU
/usr/bin/ld: cannot find -lglfw3
makefile:44: recipe for target 'opengl_glut' failed
collect2: error: ld returned 1 exit status
make: *** [opengl_glut] Error 1

How to fix those errors?

Phantom
  • 23
  • 1
  • 5

1 Answers1

0

For your first problem link to glut by adding -lglut. You have to link to libraries you use. Its not enough to just include the header.

For your second problem remove glfw3 from the libraries. Not sure why that's there. You're using glut not glfw. If the tutorial also uses glfw then the other option is to install it, or find a tutorial that doesn't.

Jason C
  • 38,729
  • 14
  • 126
  • 182