【问题标题】:GLFW Won't Link CorrectlyGLFW 无法正确链接
【发布时间】:2013-09-11 15:10:42
【问题描述】:

所以最近我开始了一个涉及 GLFW(64 位,带有 GLEW)的项目。但是,我似乎无法正确链接。这是我的设置方式:

操作系统:Windows 8 64 位

编译器:mingw64

IDE:日食

我的简单测试程序:

#include <stdio.h>
#include <stdlib.h>

#define GLEW_STATIC
#include <gl/glew.h>
#include <gl/glfw3.h>

int main(void) {
    glfwInit();
puts("Hello, World!");
    return (EXIT_SUCCESS);
}

我是如何设置链接的:http://i.imgur.com/yyISNtZ.png

错误(注意这些仅在引用任何 GLFW 函数时发生。它们不会通过简单地包含标头而发生):

13:33:00 **** Incremental Build of configuration Release for project MementoLibrary ****
Info: Internal Builder is used for build
gcc -O3 -Wall -c -fmessage-length=0 -o "src\\MementoLibrary.o" "..\\src\\MementoLibrary.c" 
gcc -o MementoLibrary.exe "src\\MementoLibrary.o" -lglfw3 -lglew32s -lopengl32 
c:/mingw64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/lib/../lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x2a7): undefined reference to `__imp_CreateDCW'
c:/mingw64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/lib/../lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x2e9): undefined reference to `__imp_GetDeviceCaps'
c:/mingw64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/lib/../lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x2fb): undefined reference to `__imp_GetDeviceCaps'
c:/mingw64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/lib/../lib/libglfw3.a(win32_monitor.c.obj):win32_monitor.c:(.text+0x31e): undefined reference to `__imp_DeleteDC'
c:/mingw64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/bin/ld.exe: c:/mingw64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/4.8.1/../../../../x86_64-w64-mingw32/lib/../lib/libglfw3.a(win32_monitor.c.obj): bad reloc address 0x0 in section `.pdata'
collect2.exe: error: ld returned 1 exit status

【问题讨论】:

  • 它正在寻找__imp... 的事实意味着它正在尝试进行DLL 导入。除非您在 MinGW 中自己编译 glfw(MinGW 无法链接到 MSVC 创建的 DLL),否则它可能无法使用 DLL。你有 glfw 的静态链接版本吗?
  • @AndonM.Coleman:我实际上已经使用 DLL 版本成功运行了它。但是,如果可能的话,我宁愿将它静态链接,让我无法让它与静态编译一起工作。我应该自己编译吗?
  • 可能不是,我只是看了一下网站。二进制发行版包括 MinGW 的静态和动态库。这应该只是使用正确的库的问题。

标签: c gcc glew glfw


【解决方案1】:

您的静态 GLFW 库是在启用 _GLFW_NO_DLOAD_WINMM 编译时宏的情况下编译的。这个和其他类似的宏可以在 GLFW 配置头中找到。

定义它会导致 GLFW 假设您将链接到 winmm(winmm.lib 在 Visual C++ 上或 libwinmm.a 在 MinGW 上)。这不是库静态版本的默认设置,所以我假设您已经自己编译了它。您可以将 winmm 添加到链接时依赖项中,也可以在编译 GLFW 时不定义 _GLFW_NO_DLOAD_WINMM

任何一种解决方案都应该使您的程序链接。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-05-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-09-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多