为什么我的程序无法链接?
我正在做一个 opengl 程序,并找到了一个可以实现我想要的功能的示例,但是当我尝试编译它时,使用 gcc -o picksquare picksquare.c -lglut
我明白了:
/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
代码示例在这里: http://www.opengl.org/resources/code/samples/redbook /picksquare.c
感谢您的回答,但是使用 -lglu 调用表示找不到 glu,并且使用 -lGL 调用给出了相同的未定义引用。这个胶是什么?有谁知道吗?
I'm doing a opengl program, and found an example that does what I want, but when I try to compile it, usinggcc -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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
试试这个:
这应该可以正常工作。上面句子中的最后一个单词是lGLU(不是one,而是代表lion的l)。
Try this:
This should work fine. The last word in the above sentence is lGLU (not one but l for lion) .
因为您正在调用 GLU 库中的函数(与 GLUT 不同),而不链接到它。
将
-lglu
添加到命令行中。请注意,失败的函数以
glu
作为前缀,而不是glut
。如果添加 -lglu 给您带来新的错误,这可能意味着您的开发系统没有安装 GLU 库。它是一个独立于 OpenGL 的可选库,因此仅仅因为您安装了 OpenGL 的开发支持,并不能保证您也拥有 GLU 的开发支持。
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, notglut
.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.
看起来您没有安装必要的库或者您需要将 LD_LIBRARY_PATH 指向正确的位置才能获取 libglut.so。
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,对于 gluOrtho2D 和公司您必须链接到 libGL,这意味着您必须在命令行上添加
-lGL
开关。AFAIK, for
gluOrtho2D
& co. you have to link against libGL, which means you have to add a-lGL
switch on your command line.好的,发现问题了,我没有将 glu 库添加到 gcc 编译器中,addind '-lGLU' 解决了问题。无论如何,谢谢你们!!
Ok, found the problem, I wasn't adding the glu library to the gcc compiler, addind '-lGLU' solved the problem. Thanx anyways guys!!