2

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?

dasen
  • 389
  • 2
  • 8
  • 13
  • You're probably missing some other libraries needed in addition to glut http://www.cplusplus.com/forum/unices/2736/ – learnvst Nov 17 '10 at 14:32
  • Again, linking problems has nothing to do with opengl or glu. Please remove those tags. As you obviously use gcc, 'gcc' would be a better tag replacement. Just because your program uses $API doesn't mean that the API tag is relevant for the question. Stop abusing tags this way. –  Nov 17 '10 at 14:56
  • Nevermind, I did it for you. Just remember this next time you post a question. Thanks. –  Nov 17 '10 at 14:59
  • Also, please stop making duplicate questions. This is is a linker problem exactly like you last question you asked Nov 14th: http://stackoverflow.com/q/4179079/95077 The only difference is that you get unresolved symbols to another library. –  Nov 18 '10 at 13:28

5 Answers5

2

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) .

Cosmin
  • 21,216
  • 5
  • 45
  • 60
samaraga
  • 21
  • 2
1

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.

unwind
  • 391,730
  • 64
  • 469
  • 606
0

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.

jbremnant
  • 894
  • 6
  • 6
0

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

Matteo Italia
  • 123,740
  • 17
  • 206
  • 299
0

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

dasen
  • 389
  • 2
  • 8
  • 13