我已将 .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;
}
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
我已经转到项目 > 属性 > 配置属性 > 链接器 > 在附加依赖项中添加了以下内容:
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)
为了更好地衡量,我还将“忽略所有默认库”设置为“否”。
我知道我应该链接:opengl32.lib、GLFW.lib、glu32.lib、kernel32.lib 和 user32.lib
不幸的是,LNK 2019 问题仍然存在。真的不确定为什么。非常感谢所有帮助。
最佳答案
外部名称表明您的项目正在为 64 位目标构建(32 位 DLL 导出通常具有 stdcall 调用约定使用的 @nn
后缀)。我敢打赌你的库是为 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>
关于c++ - 无法链接 GLFW C++;添加了 .dll、.h、.lib,但仍然获取 LNK2019,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15467872/