C++ Visual Studio 11 GLFW 外部符号错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20223198/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio 11 GLFW external symbol error
提问by Michael
The basic code I use is the example from http://www.glfw.org/documentation.html
我使用的基本代码是来自http://www.glfw.org/documentation.html的示例
I get this output:
我得到这个输出:
1>------ Build started: Project: ConsoleApplication1, Configuration: Debug Win32 ------
1> Quelle.cpp
1>Quelle.obj : error LNK2019: unresolved external symbol _glfwInit referenced in function _main
1>Quelle.obj : error LNK2019: unresolved external symbol _glfwTerminate referenced in function _main
1>Quelle.obj : error LNK2019: unresolved external symbol _glfwCreateWindow referenced in function _main
1>Quelle.obj : error LNK2019: unresolved external symbol _glfwWindowShouldClose referenced in function _main
1>Quelle.obj : error LNK2019: unresolved external symbol _glfwPollEvents referenced in function _main
1>Quelle.obj : error LNK2019: unresolved external symbol _glfwMakeContextCurrent referenced in function _main
1>Quelle.obj : error LNK2019: unresolved external symbol _glfwSwapBuffers referenced in function _main
1>C:\Users\MICHAEL\documents\visual studio 2012\Projects\ConsoleApplication1\Debug\ConsoleApplication1.exe : fatal error LNK1120: 7 unresolved externals
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
The glfw3.h is in the VC/include directory. I've also added the glfw3.lib to the VC/lib folder and I added the glfw3.lib as an additional dependency to the linker input but I still get this errors.
glfw3.h 位于 VC/include 目录中。我还将 glfw3.lib 添加到 VC/lib 文件夹中,并将 glfw3.lib 添加为链接器输入的附加依赖项,但我仍然收到此错误。
Any Idea why? I've used the precompiled binaries (which support MSVC2012 and 64x) http://www.glfw.org/download.html
任何想法为什么?我使用了预编译的二进制文件(支持 MSVC2012 和 64x)http://www.glfw.org/download.html
回答by Michael
Ok, after very much trial and error I solved it.
好的,经过反复试验,我解决了它。
- Use the 32-bit binaries
- Right click on the project -> Properties -> VC++
- Include Directories: C:\Users\MICHAEL\Desktop\glfw-3.0.3.bin.WIN32\include;$(IncludePath)
- Library Directories: C:\Users\MICHAEL\Desktop\glfw-3.0.3.bin.WIN32\lib-msvc110;$(LibraryPath)
- Linker -> Input -> Additional Dependencies add
- glfw3.lib and opengl32.lib
- 使用 32 位二进制文件
- 右键单击项目-> 属性-> VC++
- 包含目录:C:\Users\MICHAEL\Desktop\glfw-3.0.3.bin.WIN32\include;$(IncludePath)
- 库目录:C:\Users\MICHAEL\Desktop\glfw-3.0.3.bin.WIN32\lib-msvc110;$(LibraryPath)
- 链接器 -> 输入 -> 附加依赖项添加
- glfw3.lib 和 opengl32.lib
That solved it for me.
那为我解决了。
回答by Lywx
This is my solution if someone is intended to use 64 bit version of GLFW:
如果有人打算使用 64 位版本的 GLFW,这是我的解决方案:
- Get GFLW source code from github.
- Using CMake to generate 64 bit Visual Studio sln.
- Configure the glfw using proper settings:
- 从 github 获取 GFLW 源代码。
- 使用 CMake 生成 64 位 Visual Studio sln。
- 使用适当的设置配置 glfw:
In case of dynamic library:
Project -> Configuration -> C/C++ -> Code Generation -> Runtime Library -> Multi-threaded Debug DLL (/MDd)
In case of static library:
Project -> Configuration -> C/C++ -> Code Generation -> Runtime Library -> Multi-threaded Debug (/MTd)
如果是动态库:
项目 -> 配置 -> C/C++ -> 代码生成 -> 运行库 -> 多线程调试 DLL (/MDd)
如果是静态库:
项目 -> 配置 -> C/C++ -> 代码生成 -> 运行库 -> 多线程调试 (/MTd)
- Build the glfw project.
Link the following binary in your project:
glfw3.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib;glfw3.lib
Also configure your project using corresponding /MDd or /MTd compiler flag and configure it to build on x64.
- Build.
- 构建 glfw 项目。
在您的项目中链接以下二进制文件:
glfw3.lib;opengl32.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;comdlg32.lib;advapi32.lib;glfw3.lib
还可以使用相应的 /MDd 或 /MTd 编译器标志配置您的项目,并将其配置为在 x64 上构建。
- 建造。
回答by lucac
Make sure that your platform is set to x64 or 32 based on what version you're using. I tried getting the 64 bit platform and I kept running into issues until I noticed that my active platform in Visual Studio was win32. Go to the configuration manager and make sure its set to 64
确保根据您使用的版本将您的平台设置为 x64 或 32。我尝试使用 64 位平台,但一直遇到问题,直到我注意到 Visual Studio 中的活动平台是 win32。转到配置管理器并确保将其设置为 64
回答by emllnd
I do not have the needed reputation to comment on the accepted answer (by Michael), but I'd like to note that I got his method working. What I needed to correct was switching the include and library directories BEFORE the rest of the IncludePath/LibraryPath instead of AFTER it.
我没有必要的声誉来评论接受的答案(迈克尔),但我想指出我让他的方法起作用了。我需要更正的是在 IncludePath/LibraryPath 的其余部分之前而不是在它之后切换包含和库目录。