为啥 glut.h 会在 CodeBlocks 中弹出一堆未定义的引用?

Posted

技术标签:

【中文标题】为啥 glut.h 会在 CodeBlocks 中弹出一堆未定义的引用?【英文标题】:Why does glut.h pop up with a bunch of undefined references in CodeBlocks?为什么 glut.h 会在 CodeBlocks 中弹出一堆未定义的引用? 【发布时间】:2014-02-21 04:34:34 【问题描述】:

我想在这里理解一些东西。如果我从 OpenGL 游戏编程构建第一个程序并在发布模式下运行它,一切正常。我在 OpenGL 窗口中渲染了立方体。但是,如果我在调试模式下编译和运行,就会弹出 glut.h,其中包含大量未定义的引用。我知道这里出了点问题,我不应该更改库文件,所以我想弄清楚这一点。以下是所有错误:

||=== Build: Debug in chapter1 (compiler: GNU GCC Compiler) ===|
obj\Debug\chapter1.o||In function `glutInit_ATEXIT_HACK':|
H:\AllCode\include\glut.h|486|undefined reference to `__glutInitWithExit@12'|
obj\Debug\chapter1.o||In function `glutCreateWindow_ATEXIT_HACK':|
H:\AllCode\include\glut.h|503|undefined reference to `__glutCreateWindowWithExit@8'|
obj\Debug\chapter1.o||In function `glutCreateMenu_ATEXIT_HACK':|
H:\AllCode\include\glut.h|549|undefined reference to `__glutCreateMenuWithExit@8'|
obj\Debug\chapter1.o||In function `main':|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|71|undefined reference to `glutInitDisplayMode@4'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|74|undefined reference to `glutInitWindowSize@8'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|75|undefined reference to `glutInitWindowPosition@8'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|81|undefined reference to `glutDisplayFunc@4'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|82|undefined reference to `glutReshapeFunc@4'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|83|undefined reference to `glutMouseFunc@4'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|84|undefined reference to `glutKeyboardFunc@4'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|85|undefined reference to `glutIdleFunc@4'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|89|undefined reference to `glutMainLoop@0'|
obj\Debug\chapter1.o||In function `Z10Initializev':|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|102|undefined reference to `__gxx_personality_sj0'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|102|undefined reference to `_Unwind_SjLj_Register'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|108|undefined reference to `glutSetMenu@4'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|109|undefined reference to `glutAddMenuEntry@8'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|110|undefined reference to `glutAttachMenu@4'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|134|undefined reference to `_Unwind_SjLj_Resume'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|134|undefined reference to `_Unwind_SjLj_Unregister'|
obj\Debug\chapter1.o||In function `Z12MouseHandleriiii':|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|156|undefined reference to `glutPostRedisplay@0'|
obj\Debug\chapter1.o||In function `Z15KeyboardHandlerhii':|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|177|undefined reference to `glutPostRedisplay@0'|
obj\Debug\chapter1.o||In function `Z15MainMenuHandleri':|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|197|undefined reference to `glutPostRedisplay@0'|
obj\Debug\chapter1.o||In function `Z7Animatev':|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|208|undefined reference to `glutPostRedisplay@0'|
obj\Debug\chapter1.o||In function `Z7Displayv':|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|275|undefined reference to `glutSwapBuffers@0'|
obj\Debug\chapter1.o||In function `Z11LoadTexturePcRj':|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|287|undefined reference to `__gxx_personality_sj0'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|287|undefined reference to `_Unwind_SjLj_Register'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|292|undefined reference to `auxDIBImageLoadA@4'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|311|undefined reference to `_Unwind_SjLj_Resume'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|313|undefined reference to `_Unwind_SjLj_Unregister'|
obj\Debug\chapter1.o||In function `Z9DrawScene12rendermode_t':|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|323|undefined reference to `__gxx_personality_sj0'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|323|undefined reference to `_Unwind_SjLj_Register'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|389|undefined reference to `_Unwind_SjLj_Resume'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|389|undefined reference to `_Unwind_SjLj_Resume'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|389|undefined reference to `_Unwind_SjLj_Resume'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|389|undefined reference to `_Unwind_SjLj_Unregister'|
obj\Debug\chapter1.o||In function `Z8DrawCubev':|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|399|undefined reference to `__gxx_personality_sj0'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|399|undefined reference to `_Unwind_SjLj_Register'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|462|undefined reference to `_Unwind_SjLj_Resume'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|462|undefined reference to `_Unwind_SjLj_Unregister'|
obj\Debug\chapter1.o||In function `Z11DrawSurfacev':|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|472|undefined reference to `__gxx_personality_sj0'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|472|undefined reference to `_Unwind_SjLj_Register'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|510|undefined reference to `_Unwind_SjLj_Resume'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|510|undefined reference to `_Unwind_SjLj_Unregister'|
obj\Debug\chapter1.o||In function `ZN11CHiResTimer17GetElapsedSecondsEm':|
H:\My Documents\Coding\OpenGL\chapter1\HiResTimer.h|47|undefined reference to `__gxx_personality_sj0'|
H:\My Documents\Coding\OpenGL\chapter1\HiResTimer.h|47|undefined reference to `_Unwind_SjLj_Register'|
H:\My Documents\Coding\OpenGL\chapter1\HiResTimer.h|59|undefined reference to `_Unwind_SjLj_Resume'|
H:\My Documents\Coding\OpenGL\chapter1\HiResTimer.h|59|undefined reference to `_Unwind_SjLj_Unregister'|
obj\Debug\chapter1.o||In function `ZN11CHiResTimer6GetFPSEm':|
H:\My Documents\Coding\OpenGL\chapter1\HiResTimer.h|70|undefined reference to `__gxx_personality_sj0'|
H:\My Documents\Coding\OpenGL\chapter1\HiResTimer.h|70|undefined reference to `_Unwind_SjLj_Register'|
H:\My Documents\Coding\OpenGL\chapter1\HiResTimer.h|84|undefined reference to `_Unwind_SjLj_Resume'|
||More errors follow but not being shown.|
||Edit the max errors limit in compiler options...|
||=== Build failed: 50 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

这里发生了一些奇怪的事情......我没有将 AllCode 链接到任何地方。我在链接器或搜索目录设置中没有任何内容。那么 AllCode 是如何被引用的呢?它从哪里获取这些信息以及如何更改它?

据我了解,我需要让这个东西在调试和发布模式下编译和运行,这样所有错误都得到解决。是我错了吗?

我的系统是 Windows 7 64 位。但是我正在运行 Code::Blocks 13.12 32 位。我已经安装了非 MinGW 版本,然后安装了 MinGW(也是 32 位)并将 Code::Blocks 链接到该版本。使用 MinGW GCC 编译器,g++ for c++,构建为 32 位。

在 MinGW\bin 目录中,我放置了 OpenGL32.dll 和其他 OpenGL dll。进入 MinGW\Include\GL 我已经复制了 OpenGL .h 文件。我在这里做错了吗?

我想了解如何正确设置,以便编译和运行任何 OpenGL 代码,即使它已有 20 年左右的历史。我不知道这样做的正确方法。我会很感激一些建议和帮助。

更新: 所以我找到了一个 libglut32win.a 文件,然后添加它,或者在编译器/链接器设置/其他链接器选项下输入 -lglut32win,阻止 glut 弹出错误。相反,我得到了这些:

||=== Build: Debug in chapter1 (compiler: GNU GCC Compiler) ===|
obj\Debug\chapter1.o||In function `Z10Initializev':|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|102|undefined reference to `__gxx_personality_sj0'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|102|undefined reference to `_Unwind_SjLj_Register'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|134|undefined reference to `_Unwind_SjLj_Resume'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|134|undefined reference to `_Unwind_SjLj_Unregister'|
obj\Debug\chapter1.o||In function `Z11LoadTexturePcRj':|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|287|undefined reference to `__gxx_personality_sj0'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|287|undefined reference to `_Unwind_SjLj_Register'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|292|undefined reference to `auxDIBImageLoadA@4'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|311|undefined reference to `_Unwind_SjLj_Resume'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|313|undefined reference to `_Unwind_SjLj_Unregister'|
obj\Debug\chapter1.o||In function `Z9DrawScene12rendermode_t':|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|323|undefined reference to `__gxx_personality_sj0'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|323|undefined reference to `_Unwind_SjLj_Register'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|389|undefined reference to `_Unwind_SjLj_Resume'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|389|undefined reference to `_Unwind_SjLj_Resume'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|389|undefined reference to `_Unwind_SjLj_Resume'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|389|undefined reference to `_Unwind_SjLj_Unregister'|
obj\Debug\chapter1.o||In function `Z8DrawCubev':|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|399|undefined reference to `__gxx_personality_sj0'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|399|undefined reference to `_Unwind_SjLj_Register'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|462|undefined reference to `_Unwind_SjLj_Resume'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|462|undefined reference to `_Unwind_SjLj_Unregister'|
obj\Debug\chapter1.o||In function `Z11DrawSurfacev':|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|472|undefined reference to `__gxx_personality_sj0'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|472|undefined reference to `_Unwind_SjLj_Register'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|510|undefined reference to `_Unwind_SjLj_Resume'|
H:\My Documents\Coding\OpenGL\chapter1\chapter1.cpp|510|undefined reference to `_Unwind_SjLj_Unregister'|
obj\Debug\chapter1.o||In function `ZN11CHiResTimer17GetElapsedSecondsEm':|
H:\My Documents\Coding\OpenGL\chapter1\HiResTimer.h|47|undefined reference to `__gxx_personality_sj0'|
H:\My Documents\Coding\OpenGL\chapter1\HiResTimer.h|47|undefined reference to `_Unwind_SjLj_Register'|
H:\My Documents\Coding\OpenGL\chapter1\HiResTimer.h|59|undefined reference to `_Unwind_SjLj_Resume'|
H:\My Documents\Coding\OpenGL\chapter1\HiResTimer.h|59|undefined reference to `_Unwind_SjLj_Unregister'|
obj\Debug\chapter1.o||In function `ZN11CHiResTimer6GetFPSEm':|
H:\My Documents\Coding\OpenGL\chapter1\HiResTimer.h|70|undefined reference to `__gxx_personality_sj0'|
H:\My Documents\Coding\OpenGL\chapter1\HiResTimer.h|70|undefined reference to `_Unwind_SjLj_Register'|
H:\My Documents\Coding\OpenGL\chapter1\HiResTimer.h|84|undefined reference to `_Unwind_SjLj_Resume'|
H:\My Documents\Coding\OpenGL\chapter1\HiResTimer.h|84|undefined reference to `_Unwind_SjLj_Unregister'|
||=== Build failed: 31 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

那么这是什么意思呢?

【问题讨论】:

我现在忘记了它的确切细节,因为它是很久以前的事了。但是,当我第一次在 windows 下使用 C::B 尝试 Glut 时,我遇到了(我认为)类似的问题(可能也是 linux,我忘记了)我的解决方案是下载并使用 glut 替代品 freeglut。你可以在这里找到它:freeglut.sourceforge.net 编辑: 刚刚检查了 CodeBlocks\MinGW\lib 文件夹 - 没有文件名 libglut.a - 这就是我安装 freeglut 的原因 - glut 的 lib 文件不是t 可用于 C::B 安装。 (可能是 minGW 的事情)无论如何,freeglut 对我有用。不要忘记链接它! 【参考方案1】:

这些是您未链接到库时收到的标准错误。您的 Release 构建设置可能有一个链接到 glut 的条目,但 Debug 构建设置没有。如果您希望一个库在 Release 和 Debug 中都链接,您需要在项目级别而不是构建级别添加它。

【讨论】:

以上是关于为啥 glut.h 会在 CodeBlocks 中弹出一堆未定义的引用?的主要内容,如果未能解决你的问题,请参考以下文章

CodeBlocks_OpenGL配置

codeblocks运行opengl

Code Blocks中配置OpenGL

MinGW 文件夹代码块中没有 GL 文件夹用于 glut

opengl程序问题,为啥只有白屏?

为啥codeblocks列表原文件显示不出来