【发布时间】:2014-03-27 08:38:37
【问题描述】:
我一直在尝试使用 C++ 测试 GLFW,但一直遇到链接器问题。我对 C++ 相当陌生,虽然我有 Java 和 C# 方面的经验,但直接使用编译器对我来说是相当新的。这是我的设置信息。
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 `CreateDCW@16'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x358): undefined reference to `GetDeviceCaps@8'
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 `GetDeviceCaps@8'
c:/mingw/bin/../lib/gcc/mingw32/4.8.1/../../../libglfw3.a(win32_monitor.c.obj):win32_monitor .c:(.text+0x39e): undefined reference to `DeleteDC@4'
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 库,但无法让它们工作。
【问题讨论】:
-
您好像错过了那里的图书馆。
CreateDCW、GetDeviceCaps和DeleteDC都存在于gdi32.dll中 - 您至少需要添加gdi32导入库。只需按照添加glfw3和opengl32库的方式添加即可。 -
非常感谢!我为此苦苦挣扎了很长时间,我不知道 gdi32 库,它在任何地方都没有提到,我不知道如何评价你的评论或选择最佳答案,但你是一个巨大的帮助!
-
不客气。我有“Win32API.hlp”和“win32sdk.hlp”的旧副本。在每一个中,都有一个标记为“快速信息”的按钮,其中列出了 (a) 声明函数的 .h 文件和 (b) 包含实际使用 dll 文件所需的代码。我发现它们是无价的。如果您在网上找不到任何东西,需要离线帮助,请给我发电子邮件,我会转发给您。电子邮件在我的个人资料页面上。
-
问题解决后,请不要在标题后面加上“已解决”之类的。只需发布答案并将其标记为已接受。 (或者让@enhzflep 发布答案)。这对可能阅读本文并对解决方案感兴趣的其他人更有帮助。
-
我的错误,我已经继续并发布了对我有用的解决方案作为答案。
标签: c++ compiler-errors qt-creator glfw mingw32