Visual Studio 11 GLFW external symbol error
Asked Answered
M

5

8

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

Mansard answered 26/11, 2013 at 16:54 Comment(5)
Could be a 32-bit/64-bit conflict. Which one did you download, and which one are you compiling for?Hangchow
I've downloaded the 64-bit Windows binaries because I have a 64-bit Windows and my Visual Studio is 64-bit but I compile as 32-bit. I will try it with the 32-bit version and tell you if it worked.Mansard
Nope. Exactly the same errors with the 32-bit binariesMansard
Note: you shouldn't go adding things to the VC install dir; place them alongside your project instead, and set your project's include and lib paths appropriately. VC may look in locations you don't expect when looking for lib files (e.g. 64/32 bit libs are located in different places). It's an implementation detail that you should be ignoring.Insufflate
Ok thanks. I removed it from the VC dir and set the lib path to the new dir. The solution got deleted - by the way, it didn't workedMansard
M
27

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.

Mansard answered 27/11, 2013 at 7:32 Comment(4)
Thanks, it was the adding of opengl32.lib that got me :)Detail
Wow, after 8 hours of trying you solved my problem with right the first instruction. I would have never thought that using 32-bit binaries on a 64 bit OS will solve my problem.Adenine
Thanks a lot the hello world worked for me but the example boeing.cpp still has some errorsImmortalize
When I trying to add glfw3.lib and opengl32.lib in the 6-th step, I got cannot open 'glfw3.lib' error, any suggestions to fix it?Garek
P
6

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.

Partain answered 7/3, 2016 at 5:7 Comment(0)
A
5

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

Agger answered 22/4, 2020 at 18:54 Comment(0)
B
0

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.

Burnedout answered 8/3, 2014 at 21:50 Comment(2)
could you write that out?Kindliness
Don't remember much about this issue but I would guess instead of what Michael has written try this: $(IncludePath);C:\Users\<yourusername>\Desktop\glfw-3.0.3.bin.WIN32\include ---- and ---- $(LibraryPath);C:\Users\<yourusername>\Desktop\glfw-3.0.3.bin.WIN32\lib-msvc110Burnedout
F
0

Besides adding glfw3.lib and opengl32.lib to the linker dependencies, I've also added gdi32.lib. This solved my linker issues on VS2019 while using glfw.

#pragma comment(lib, "gdi32.lib")
#pragma comment(lib, "opengl32.lib")
#pragma comment(lib, "glfw3.lib")
Freespoken answered 5/5, 2022 at 5:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.