Visual Studio 11 GLFW external symbol error

限于喜欢 提交于 2019-12-05 02:02:27

问题


The basic code I use is the example from 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.

Any Idea why? I've used the precompiled binaries (which support MSVC2012 and 64x) http://www.glfw.org/download.html


回答1:


Ok, after very much trial and error I solved it.

  1. Use the 32-bit binaries
  2. Right click on the project -> Properties -> VC++
  3. Include Directories: C:\Users\MICHAEL\Desktop\glfw-3.0.3.bin.WIN32\include;$(IncludePath)
  4. Library Directories: C:\Users\MICHAEL\Desktop\glfw-3.0.3.bin.WIN32\lib-msvc110;$(LibraryPath)
  5. Linker -> Input -> Additional Dependencies add
  6. glfw3.lib and opengl32.lib

That solved it for me.




回答2:


This is my solution if someone is intended to use 64 bit version of GLFW:

  1. Get GFLW source code from github.
  2. Using CMake to generate 64 bit Visual Studio sln.
  3. Configure the glfw using proper settings:

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)

  1. Build the glfw project.
  2. 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
    
  3. Also configure your project using corresponding /MDd or /MTd compiler flag and configure it to build on x64.

  4. Build.



回答3:


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.



来源:https://stackoverflow.com/questions/20223198/visual-studio-11-glfw-external-symbol-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!