MinGW和GLUT未定义引用'_imp ____ glutInitWithExit @ 12'

问题描述 投票:3回答:2

我在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

这里有什么想法? system32和SysWOW64中都存在glut32.dll

c++ windows glut freeglut windows64
2个回答
0
投票

你需要链接到过剩二进制:

g++ GLtest1.cpp -lglut32

0
投票

我的情况:我将lib文件和bin文件从64位切换到32位。它奏效了。

© www.soinside.com 2019 - 2024. All rights reserved.