2014-02-25 121 views
5

我一直试图用C++测试GLFW很长一段时间,并且存在不断的链接器问题。我对C++相当陌生,虽然我有Java和C#的经验,但直接使用编译器对我来说是相当新的。这是我的设置信息。GLFW MinGW链接错误

IDE:Qt Creator的

操作系统:Windows 7 64位

编译:MINGW32 4.8.1

01:23:26: Starting: "C:\MinGW\bin\mingw32-make.exe" 
C:/MinGW/bin/mingw32-make -f Makefile.Debug 
mingw32-make[1]: Entering directory 'A:/workspace_cpp/Test-Debug' 
g++ -Wl,-subsystem,console -mthreads -o debug\Test.exe debug/main.o -lglfw3 -lopengl32 
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libglfw3.a(win32_monitor.c.obj):win32_monitor.::(.text+0x2c7): undefined reference to `[email protected]' 
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x358): undefined reference to `[email protected]' 
Makefile.Debug:77: recipe for target 'debug\Test.exe' failed 
mingw32-make[1]: Leaving directory 'A:/workspace_cpp/Test-Debug' 
Makefile:34: recipe for target 'debug' failed 
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x370): undefined reference to `[email protected]' 
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libglfw3.a(win32_monitor.c.obj):win32_monitor .c:(.text+0x39e): undefined reference to `[email protected]' 
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../../mingw32/bin/ld.exe:  c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libglfw3.a(win32_monitor.c.obj): 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 

我测试的代码是关于GLFW Documentation Page的代码,我我正在使用我自己的GLFW,and have already tried this和其他几个潜在的解决方案。我尝试过使用预编译的GLFW mingw库,但是我无法让它们工作。

+2

看起来你错过了那里的一个图书馆。 'CreateDCW','GetDeviceCaps'和'DeleteDC'都存在于'gdi32.dll'中 - 你至少需要添加'gdi32'导入库。只需添加它,就像添加'glfw3'和'opengl32'库一样。 – enhzflep

+0

非常感谢!我一直在为此苦苦挣扎,我没有意识到gdi32库,它在任何地方都没有提及,我不知道如何注册您的评论或选择一个最好的答案,但你是一个巨大的帮助! –

+0

不客气。我有“Win32API.hlp”和“win32sdk.hlp”的旧副本。在其中的每一个中,都有一个标有“快速信息”的按钮,其中列出了(a)函数声明的.h文件和(b)包含实际文件的.lib(或.a,如果是gcc)文件代码需要使用dll文件。我发现它们是无价的。如果你在网上找不到任何东西,为了脱机帮助,请给我发一封电子邮件,我会向你转发一封。电子邮件在我的个人资料页面。 – enhzflep

回答

13

张贴由enhzflep的解决方案是包含编译时,作出所有必要的接头-lglfw3 -lgdi32 -lopengl32到GDI32库,因为缺少方法,CreateDCWGetDeviceCapsDeleteDC都内的libgdi32.aMinGW lib文件夹C:\MinGW\lib\libgdi32.a在这种情况下, 。