Undefined reference to gluPerspective

I am trying to learn OpenGL using these tutorials:

They told me to download a source file and compile it. It should result in a spinning cube.

However when I try to compile it it gives me the following error:

kobe@kobe-laptop:~/Tutorials/Cube$ make
g++ -Wall -o cube main.cpp imageloader.cpp -lglut
imageloader.cpp: In function ‘Image* loadBMP(const char*)’:
imageloader.cpp:141: warning: suggest parentheses around ‘&&’ within ‘||’
/tmp/ccDxFyfp.o: In function `handleResize(int, int)':
main.cpp:(.text+0x18b): undefined reference to `gluPerspective'
collect2: ld returned 1 exit status
make: *** [cube] Error 1

I have got all the header files that are required installed. How can I solve this problem?

Thanks in advance!

This isn’t a header file issue. Header files are for compiling. This is a linking issue. It needs a library that contains gluPerspective. That library is libGLU.


g++ -Wall -o cube main.cpp imageloader.cpp -lglut -lGLU -lGL

Thank you, that worked!