我是一名初学者,曾经涉猎Python一年,现在开始接触C++。我安装了MinGW,并且一切都正常工作,直到我安装了freeglut。当我运行以下代码时:
#include <gl/glut.h>
int main()
{
return 0;
}
使用:
C:\code\cpp>g++ GLtest1.cpp
I get this:
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两个文件夹中。