对符号“gluLookAt”的未定义引用
我正在使用 Fedora 16。我已经安装了 freeglut 和 freeglut-devel 软件包。我尝试运行一个简单的 opengl 程序,但出现以下错误
gcc cube.c -o cube -lglut
/usr/bin/ld: /tmp/ccSFol4w.o: undefined reference to symbol 'gluLookAt'
/usr/bin/ld: note: 'gluLookAt' is defined in DSO /usr/lib/libGLU.so.1 so try adding it to the linker command line
/usr/lib/libGLU.so.1: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
I'm using Fedora 16. I've installed freeglut and freeglut-devel packages. I tried to rum a simple opengl program, but i'm getting the following error
gcc cube.c -o cube -lglut
/usr/bin/ld: /tmp/ccSFol4w.o: undefined reference to symbol 'gluLookAt'
/usr/bin/ld: note: 'gluLookAt' is defined in DSO /usr/lib/libGLU.so.1 so try adding it to the linker command line
/usr/lib/libGLU.so.1: could not read symbols: Invalid operation
collect2: ld returned 1 exit status
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
编译:
g++sampleCode.cpp -lglut -lGL -lGLU
运行:
./a.out
就是你的答案。
Compile :
g++ sampleCode.cpp -lglut -lGL -lGLU
run :
./a.out
is your answer.
你必须链接一些 gl 库。
You have to link some gl libraries.
我认为你应该查阅一些关于编译器、链接器和库的介绍文本,即在构建程序时这些部分是如何组合在一起的。本质上,链接器是在告诉您,存在一些未解决的问题,因此无法完成程序的链接。添加库是通过带有库名称(在您的情况下为 GLU)的 -l 开关来进行的,而不是通过为其提供库文件的完整路径。
I think you should consult some introduction text on compilers, linkers and libraries, i.e. how the pieces come together when building a program. In essence the linker is telling you, that there are some loose ends and it cannot finish linking the program due to them. Adding a library happens by the -l switch with library name (GLU in your case), not by giving it a full path to the library file.
照它说的去做
do what it says
我在 Ubuntu 12.04 LTS 中遇到了完全相同的问题,当时我写道:
但后来我在网上发现有些人还添加了 -lGL 和 lGLU,所以我这样做了,现在可以编译了:
I got the exact same problem in Ubuntu 12.04 LTS when I wrote:
But then I found on the web that some people also added -lGL and lGLU so I did it and it compiles now: