2014-01-18 50 views
3

我涉足Python一年,并且正在启动C++,因此我是一个noob。我安装了MinGW,并且一切正常,直到我安装了freeglut。当我运行下面的代码:MinGW和GLUT未定义引用'_imp ____ glutInitWithExit @ 12'

#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 `[email protected]' 
C:\Users\User\AppData\Local\Temp\ccABWOyv.o:GLtest1.cpp:(.text+0x3e): undefined 
reference to `[email protected]' 
C:\Users\User\AppData\Local\Temp\ccABWOyv.o:GLtest1.cpp:(.text+0x60): undefined 
reference to `[email protected]' 
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中

+0

dll文件是一个动态加载的库(在运行时需要它)。当您链接您的应用程序时,您需要链接静态库(扩展名为.a或.lib的文件)。你可以通过-L switch来告诉编译器在哪里寻找静态库(类似于-I头)。 – tumdum

回答

0

您需要链接到餍二进制:

g++ GLtest1.cpp -lglut32 
+0

1.我每次编译代码都必须链接? 2.你会推荐为Windows 64位操作系统执行“-lglut64”吗? – Frumples

+0

是的,要有工作二进制文件,你需要每次执行链接。是的,我期望对于win64,这个名字会变成glut64。 – tumdum

+0

C:\ code \ cpp> g ++ GLtest1.cpp -lglut32 c:/ mingw/bin /../ lib/gcc/mingw32/4.8.1 /../../../../ mingw32/bin /ld.exe:无法找到-lglut32 collect2.exe:错误:ld返回1退出状态 – Frumples

0

我的情况:我换的lib文件和bin文件从64位到32位。它的工作。

相关问题