dasen
dasen

Reputation: 389

Why does my program fail to link?

I'm doing a opengl program, and found an example that does what I want, but when I try to compile it, using gcc -o picksquare picksquare.c -lglut I get:

/tmp/cchE9Z0Y.o: In function `pickSquares':
picksquare.c:(.text+0x41d): undefined reference to `gluPickMatrix'
picksquare.c:(.text+0x442): undefined reference to `gluOrtho2D'
/tmp/cchE9Z0Y.o: In function `reshape':
picksquare.c:(.text+0x508): undefined reference to `gluOrtho2D'
collect2: ld returned 1 exit status

And the code example is here: http://www.opengl.org/resources/code/samples/redbook/picksquare.c

Thanx for your answer guys, but invoking with -lglu says it can't find glu, and invoking with -lGL gives the same undefined reference. What is this glu? Does anyone know?

Upvotes: 2

Views: 3040

Answers (5)

samaraga
samaraga

Reputation: 21

Try this:

gcc filename_here -lglut -lGLU

This should work fine. The last word in the above sentence is lGLU (not one but l for lion) .

Upvotes: 2

dasen
dasen

Reputation: 389

Ok, found the problem, I wasn't adding the glu library to the gcc compiler, addind '-lGLU' solved the problem. Thanx anyways guys!!

Upvotes: 0

unwind
unwind

Reputation: 400039

Because you're calling functions in the GLU library (which is not the same as GLUT), without linking to it.

Add -lglu to your command line.

Note that the functions failing have glu as their prefix, not glut.

If adding -lglu gives you a new error, that might mean you development system doesn't have the GLU library installed. It's an optionalal library independent of OpenGL, so just because you have installed development support for OpenGL there's no guarantee that you also have it for GLU.

Upvotes: 1

Matteo Italia
Matteo Italia

Reputation: 126907

AFAIK, for gluOrtho2D & co. you have to link against libGL, which means you have to add a -lGL switch on your command line.

Upvotes: 0

jbremnant
jbremnant

Reputation: 894

Looks like you don't have the necessary libraries installed or you need to point your LD_LIBRARY_PATH to a correct location to pick up libglut.so.

Upvotes: 0

Related Questions