我涉猎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中都存在
2条答案
按热度按时间c7rzv4ha1#
你需要链接到过剩二进制:
kokeuurv2#
我的例子:我把lib文件和bin文件从64位切换到32位。而且成功了。