开发者

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开发者_如何学JAVA 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?


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


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.


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.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜