无法链接GLFW C++; 添加了.dll,.h,.lib,但仍然获得了LNK2019

Dan*_*ons 2 c++ opengl properties lnk2019 glfw

我已将.dll添加到Windows/System32,将.lib添加到VS/lib,将.h添加到VS/include.

剩下的就是通过项目将其链接起来.这就是我所拥有的:


#include <glfw.h>

int main(void)
{
    /* Initialize the library */
    if (!glfwInit())
        return -1;

    /* Create a windowed mode window and its OpenGL context */
    if (!glfwOpenWindow(640, 480, 8, 8, 8, 0, 24, 0, GLFW_WINDOW))
        return -1;

    /* Loop until the user closes the window */
    while (glfwGetWindowParam(GLFW_OPENED))
    {
        /* Render here */

        /* Swap front and back buffers and process events */
        glfwSwapBuffers();
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)
1>Main.obj : error LNK2019: unresolved external symbol _glfwSwapBuffers referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol _glfwGetWindowParam referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol _glfwOpenWindow referenced in function _main
1>Main.obj : error LNK2019: unresolved external symbol _glfwInit referenced in function _main
1>C:\Users\Danny\documents\visual studio 2010\Projects\OGL2\Debug\OGL2.exe : fatal error LNK1120: 4 unresolved externals
Run Code Online (Sandbox Code Playgroud)

我去了Project> Properties> Configuration Properties> Linker>将以下内容添加到Additional Dependencies:


opengl32.lib;GLFW.lib;glu32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
Run Code Online (Sandbox Code Playgroud)

为了更好的衡量,我还将Ignore All Default Libraries设置为"No".

我知道我应该联系到: opengl32.lib, GLFW.lib, glu32.lib, kernel32.lib and user32.lib

不幸的是,LNK 2019问题依然存在.真的不确定为什么.非常感谢所有帮助.

Mic*_*urr 10

外部名称表示您的项目正在为64位目标构建(32位DLL导出通常具有@nnstdcall调用约定使用的后缀).我敢打赌你的库是为32位目标构建的.

将项目设置更改为Win32而不是x64.

我猜错了 - 未解析的外部符号,例如_glfwSwapBuffers表明你正在为32位目标构建.构建64位目标时,外部名称不会使用下划线进行修饰.

但基本解决方案是相同的 - 确保正在构建的目标与您拥有的目标相同.因此,如果您已下载64位GLFW库,请确保您的VS项目正在构建Win64目标.

在将64位GLFW二进制分发提取到以下内容之后,我能够编译并链接您的测试程序c:\temp:

C:\temp>cl /I c:\temp\glfw-2.7.7.bin.WIN64\include\GL test.cpp c:\temp\glfw-2.7.7.bin.WIN64\lib-msvc110\GLFWDLL.lib
Microsoft (R) C/C++ Optimizing Compiler Version 17.00.50727.1 for x64
Copyright (C) Microsoft Corporation.  All rights reserved.

test.cpp
Microsoft (R) Incremental Linker Version 11.00.50727.1
Copyright (C) Microsoft Corporation.  All rights reserved.

/out:test.exe
test.obj
c:\temp\glfw-2.7.7.bin.WIN64\lib-msvc110\GLFWDLL.lib

C:\temp>
Run Code Online (Sandbox Code Playgroud)