Why does my program fail to link?

≯℡__Kan透↙ 提交于 2019-12-24 02:15:27

问题


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?


回答1:


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




回答2:


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.




回答3:


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.




回答4:


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




回答5:


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



来源:https://stackoverflow.com/questions/4205380/why-does-my-program-fail-to-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!