有很多过剩错误

Having many glut errors

本文关键字:错误      更新时间:2023-10-16

>我找到了这段代码,想在我的机器上尝试:

#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++ 教程01.cpp

/

tmp/ccOoXvqJ.o: 在函数 'RenderSceneCB((' 中:

tutorial01.cpp:(.text+0xa(:未定义对"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"的未定义引用

教程01.cpp:(.text+0x5c(:未定义的引用

'glutInitWindowSize' tutorial01.cpp:(.text+0x6b(: 未定义的引用

to 'glutInitWindowPosition' tutorial01.cpp:(.text+0x75(: undefined

参考 'glutCreateWindow' 教程01.cpp:(.text+0x8b(: 未定义

参考 'glClearColor' 教程01.cpp:(.text+0x90(: 未定义

引用 'glutMainLoop' collect2:ld 返回 1 个退出状态

我想我已经在我的机器上成功安装了freeglut3-dev。你能告诉我为什么我会收到这么多错误吗?我正在使用 Ubuntu 12.04。

您看到的是链接器错误,即编译器处理的代码已成功转换为编译单元。现在,链接器尝试使可执行的,并且无法捆绑编译单元的松散端,即对 GLUT 和 OpenGL 符号的引用。你必须告诉链接器要查找其他位置,而不仅仅是编译单元和标准库。

由于您的错误消息看起来像 GCC 生成的,我建议您在编译器的命令行中添加-lGL -lglut

这些是 Glut 和 OpenGL 的链接器错误。链接器是尝试将所有目标文件链接在一起以获取exe的软件。

您需要将它们(OpenGl和Glut(与您的项目链接起来。谷歌有很多答案=(

我下载了freeglut并使用 MinGW 编译了我的 Code::blocks 中的代码,我发现您的问题出在库上,您需要链接libopengl32.alibfreeglut.a以便程序可以运行它。