GLFW MinGW link error(GLFW MinGW 链接错误)
问题描述
我尝试用 C++ 测试 GLFW 已经有一段时间了,但一直有链接器问题.我对 C++ 还很陌生,虽然我有 Java 和 C# 方面的经验,但直接使用编译器对我来说还是很陌生的.这是我的设置信息.
I've been attempting to test out GLFW with C++ for quite a while and am having constant linker issues. I am fairly new to C++, although I have experience in Java and C#, working directly with the compiler is fairly new to me. Here's my setup information.
IDE:Qt Creator
IDE: Qt Creator
操作系统:Windows 7 64 位
OS: Windows 7 64-bit
编译器:MinGW32 4.8.1
Compiler: MinGW32 4.8.1
01:23:26: Starting: "C:MinGWinmingw32-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 debugTest.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 'debugTest.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 文档页面上的代码,我是使用我自己构建的 GLFW,并且已经尝试过这个和其他几个潜在的解决方案.我曾尝试使用预构建的 GLFW mingw 库,但我无法让它们工作.
The code I'm testing is the code on the GLFW Documentation Page, I'm using my own build of GLFW, and have already tried this and several other potential solutions. I have tried using the prebuilt GLFW mingw libraries but I couldn't get them to work.
推荐答案
enhzflep 的解决方案是在编译时包含到 gdi32 库中,制作所有必要的链接器 -lglfw3 -lgdi32 -lopengl32
,作为缺失的方法,CreateDCW
、GetDeviceCaps
和DeleteDC
都在libgdi32.a
中的>MinGW
lib 文件夹 C:MinGWliblibgdi32.a
在这种情况下.
The solution as posted by enhzflep was to include to gdi32 library when compiling, making all the necessary linkers -lglfw3 -lgdi32 -lopengl32
, as the missing methods, CreateDCW
, GetDeviceCaps
and DeleteDC
are all inside of libgdi32.a
in the MinGW
lib folder C:MinGWliblibgdi32.a
in this case.
这篇关于GLFW MinGW 链接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:GLFW MinGW 链接错误


基础教程推荐
- 为 C/C++ 中的项目的 makefile 生成依赖项 2022-01-01
- 使用从字符串中提取的参数调用函数 2022-01-01
- 从 std::cin 读取密码 2021-01-01
- 在 C++ 中循环遍历所有 Lua 全局变量 2021-01-01
- Windows Media Foundation 录制音频 2021-01-01
- 如何在不破坏 vtbl 的情况下做相当于 memset(this, ...) 的操作? 2022-01-01
- 管理共享内存应该分配多少内存?(助推) 2022-12-07
- 如何使图像调整大小以在 Qt 中缩放? 2021-01-01
- 如何“在 Finder 中显示"或“在资源管理器中显 2021-01-01
- 为什么语句不能出现在命名空间范围内? 2021-01-01