【发布时间】:2013-09-30 20:25:11
【问题描述】:
我找到了这段代码,想在我的机器上试试:
#include <GL/freeglut.h>
static void RenderSceneCB()
{
glClear(GL_COLOR_BUFFER_BIT);
glutSwapBuffers();
}
static void InitializeGlutCallbacks()
{
glutDisplayFunc(RenderSceneCB);
}
int main(int argc, char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_DOUBLE|GLUT_RGBA);
glutInitWindowSize(1024, 768);
glutInitWindowPosition(100, 100);
glutCreateWindow("Tutorial 01");
InitializeGlutCallbacks();
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glutMainLoop();
return 0;
}
我得到了这些错误:
g++ tutorial01.cpp
/tmp/ccOoXvqJ.o:在函数`RenderSceneCB()'中:
tutorial01.cpp:(.text+0xa): undefined reference to `glClear'
tutorial01.cpp:(.text+0xf): 对 `glutSwapBuffers' 的未定义引用
/tmp/ccOoXvqJ.o:在函数“InitializeGlutCallbacks()”中:
tutorial01.cpp:(.text+0x1f): 对 `glutDisplayFunc' 的未定义引用
/tmp/ccOoXvqJ.o:在函数“main”中:tutorial01.cpp:(.text+0x43):
未定义对 `glutInit' tutorial01.cpp:(.text+0x4d):
的引用对 `glutInitDisplayMode' 的未定义引用
tutorial01.cpp:(.text+0x5c): 未定义的引用
`glutInitWindowSize' tutorial01.cpp:(.text+0x6b): 未定义参考
to `glutInitWindowPosition' tutorial01.cpp:(.text+0x75): undefined
参考 `glutCreateWindow' tutorial01.cpp:(.text+0x8b): undefined
参考 `glClearColor' tutorial01.cpp:(.text+0x90): undefined
对 `glutMainLoop' collect2 的引用:ld 返回 1 个退出状态
我想我已经在我的机器上成功安装了 freeglut3-dev。你能告诉我为什么我得到这么多错误吗?我使用的是 Ubuntu 12.04。
【问题讨论】:
-
您不仅需要安装 glut,还必须与它的库进行链接。您应该在关于如何构建程序的问题中添加一些内容,因为这可能是错误所在。
-
是的,我必须添加“-lglut”。谢谢。