c++ - MinGW 和 GLUT 未定义对 '_imp____glutInitWithExit@12' 的引用

标签 c++ windows glut freeglut windows64

我接触了一年的Python,正在学习c++,所以我是一个菜鸟。我安装了 MinGW 并且一切正常,直到我安装了 freeglut。当我运行以下代码时:

#include <gl/glut.h>

int main()
{
    return 0;
}

使用:

C:\code\cpp>g++ GLtest1.cpp

我明白了:

C:\Users\User\AppData\Local\Temp\ccABWOyv.o:GLtest1.cpp:(.text+0x1c): undefined
reference to `_imp____glutInitWithExit@12'
C:\Users\User\AppData\Local\Temp\ccABWOyv.o:GLtest1.cpp:(.text+0x3e): undefined
reference to `_imp____glutCreateWindowWithExit@8'
C:\Users\User\AppData\Local\Temp\ccABWOyv.o:GLtest1.cpp:(.text+0x60): undefined
reference to `_imp____glutCreateMenuWithExit@8'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: C:\Users\U
ser\AppData\Local\Temp\ccABWOyv.o: bad reloc address 0x20 in section `.eh_frame'

c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: final link
 failed: Invalid operation
collect2.exe: error: ld returned 1 exit status

我安装并重新安装了 MinGW 数次以尝试解决该问题,但无济于事。我尝试使用

#include <windows.h> 

还有。我尝试安装 64 位 .dll 文件——没有。如果有人以前遇到过这种情况,或者熟悉我的问题,欢迎提供帮助。谢谢你。我猜我需要对“链接”做些什么,但我真的不明白为什么“glut.h”应该与“gl.h”或“glu.h”有什么不同。太令人沮丧了!

更新:

我试图将一些事情联系起来。首先我这样做了:

C:\code\cpp>g++ -c -o GLtest1.exe GLtest1.cpp -I"C:\MinGW\include"

一切顺利。没有错误。然后我尝试链接周围的东西并以错误结束:

C:\code\cpp>g++ -o GLtest1.exe -L"C:\MinGW\lib" -lglut32 -opengl32
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe: cannot fin
d -lglut32
collect2.exe: error: ld returned 1 exit status

这里有什么想法吗? glut32.dll存在于System32和SysWOW64中

最佳答案

您需要链接到 glut 二进制文件:

g++ GLtest1.cpp -lglut32

关于c++ - MinGW 和 GLUT 未定义对 '_imp____glutInitWithExit@12' 的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21210895/

相关文章:

c++ - 如何在 Eclipse CDT 中启用 C++11/C++0x 支持?

c++ - fopen 抛出无效参数错误

c# - 如何获得过去10年的夏令时界限

Windows 批处理脚本 - 参数中的括号破坏程序输出到变量的分配

C++加载外部类exe

c++ - 减少 openmp 的奇怪结果

c++ - 为什么 const char* 隐式转换为 bool 而不是 std::string?

C++ 构造函数初始化多个成员

macos - 如何将 GLUT 与 libdispatch 一起使用?

python - 尝试调用未定义的函数 glutInit