Setting Up GLFW on Visual Studio

Hello all,
I am attempting to statically link to x64 bit GLFW in Visual Studio. I’ve added directories for glfw3.lib and glfw3.h, and set the runtime to Multithreaded and Multithreaded Debug. I’ve tried all the solutions I could find but I continue to get the same error messages:

1>LINK : warning LNK4098: defaultlib ‘MSVCRT’ conflicts with use of other libs; use /NODEFAULTLIB:library
1>LINK : warning LNK4286: symbol ‘free’ defined in ‘libucrtd.lib(free.obj)’ is imported by ‘glfw3.lib(win32_joystick.obj)’
1>LINK : warning LNK4286: symbol ‘free’ defined in ‘libucrtd.lib(free.obj)’ is imported by ‘glfw3.lib(wgl_context.obj)’
1>LINK : warning LNK4286: symbol ‘free’ defined in ‘libucrtd.lib(free.obj)’ is imported by ‘glfw3.lib(egl_context.obj)’
1>LINK : warning LNK4286: symbol ‘free’ defined in ‘libucrtd.lib(free.obj)’ is imported by ‘glfw3.lib(osmesa_context.obj)’
1>LINK : warning LNK4286: symbol ‘free’ defined in ‘libucrtd.lib(free.obj)’ is imported by ‘glfw3.lib(win32_monitor.obj)’
1>LINK : warning LNK4286: symbol ‘free’ defined in ‘libucrtd.lib(free.obj)’ is imported by ‘glfw3.lib(monitor.obj)’
1>LINK : warning LNK4286: symbol ‘free’ defined in ‘libucrtd.lib(free.obj)’ is imported by ‘glfw3.lib(vulkan.obj)’
1>LINK : warning LNK4286: symbol ‘free’ defined in ‘libucrtd.lib(free.obj)’ is imported by ‘glfw3.lib(win32_window.obj)’
1>LINK : warning LNK4217: symbol ‘free’ defined in ‘libucrtd.lib(free.obj)’ is imported by ‘glfw3.lib(init.obj)’ in function ‘terminate’
1>LINK : warning LNK4286: symbol ‘free’ defined in ‘libucrtd.lib(free.obj)’ is imported by ‘glfw3.lib(window.obj)’
1>LINK : warning LNK4286: symbol ‘free’ defined in ‘libucrtd.lib(free.obj)’ is imported by ‘glfw3.lib(input.obj)’
1>LINK : warning LNK4286: symbol ‘free’ defined in ‘libucrtd.lib(free.obj)’ is imported by ‘glfw3.lib(win32_init.obj)’
1>LINK : warning LNK4217: symbol ‘__stdio_common_vsprintf’ defined in ‘libucrtd.lib(output.obj)’ is imported by ‘glfw3.lib(init.obj)’ in function ‘_glfwInputError’
1>LINK : warning LNK4286: symbol ‘__stdio_common_vsprintf’ defined in ‘libucrtd.lib(output.obj)’ is imported by ‘glfw3.lib(win32_joystick.obj)’
1>LINK : warning LNK4217: symbol ‘strncmp’ defined in ‘libucrtd.lib(strncmp.obj)’ is imported by ‘glfw3.lib(context.obj)’ in function ‘_glfwRefreshContextAttribs’
1>LINK : warning LNK4286: symbol ‘strncmp’ defined in ‘libucrtd.lib(strncmp.obj)’ is imported by ‘glfw3.lib(input.obj)’
1>LINK : warning LNK4217: symbol ‘strncmp’ defined in ‘libucrtd.lib(strncmp.obj)’ is imported by ‘glfw3.lib(egl_context.obj)’ in function ‘_glfwCreateContextEGL’
1>LINK : warning LNK4217: symbol ‘strtoul’ defined in ‘libucrtd.lib(strtox.obj)’ is imported by ‘glfw3.lib(input.obj)’ in function ‘parseMapping’
1>LINK : warning LNK4217: symbol ‘qsort’ defined in ‘libucrtd.lib(qsort.obj)’ is imported by ‘glfw3.lib(monitor.obj)’ in function ‘refreshVideoModes’
1>LINK : warning LNK4217: symbol ‘qsort’ defined in ‘libucrtd.lib(qsort.obj)’ is imported by ‘glfw3.lib(win32_joystick.obj)’ in function ‘deviceCallback’
1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(wgl_context.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(egl_context.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(osmesa_context.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(monitor.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(vulkan.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(win32_window.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(init.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(window.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(win32_init.obj) : error LNK2001: unresolved external symbol __imp_calloc
1>glfw3.lib(window.obj) : error LNK2019: unresolved external symbol __imp_strncpy referenced in function glfwWindowHintString
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __imp_strncpy
1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol __imp_strncpy
1>glfw3.lib(context.obj) : error LNK2019: unresolved external symbol __imp___stdio_common_vsscanf referenced in function sscanf
1>glfw3.lib(input.obj) : error LNK2019: unresolved external symbol __imp_strcspn referenced in function glfwUpdateGamepadMappings
1>glfw3.lib(input.obj) : error LNK2019: unresolved external symbol __imp_strspn referenced in function glfwUpdateGamepadMappings
1>glfw3.lib(input.obj) : error LNK2019: unresolved external symbol __imp_realloc referenced in function glfwUpdateGamepadMappings
1>glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol __imp_realloc
1>glfw3.lib(monitor.obj) : error LNK2001: unresolved external symbol __imp_realloc
1>C:\Users\Lourdas\Desktop\games\Spark\x64\Debug\Spark.exe : fatal error LNK1120: 6 unresolved externals
1>Done building project “Spark.vcxproj” – FAILED.

This happens with 3.2 and 3.3 on VS 2015, 17 and 19
Any help is greatly appreciated,
-Aristides

Hi Arisides,

Welcome to the GLFW forum.

Using the WIn64 download from https://github.com/glfw/glfw/releases/download/3.3/glfw-3.3.bin.WIN32.zip (extracted to a dir in my example dir project) I was able to create a new empty console project in Visual Studio 2019, with a file called main.cpp with the contents of https://www.glfw.org/documentation.html, followed by adding the following settings:

Additional include directories set to the include from the downloaded and extracted glfw.

Add opengl32.lib;glfw3.lib; to the Linker->Input->Additional Dependencies before the rest of the link libraries (do not delete the default ones).

Then set Linker->General->Additional Library Directories to the lib-vc2019 or appropriate folder.

This should get you working so you can check what you did differently in your own project and figure out where things went wrong.

Cheers,

Doug.

1 Like

Thanks a million, this has bugged me all year!
It’s strange though… the solution was to revert from Multithreaded DLL to Multithreaded, even though everything is linking statically. No DLLs were generated though, so I’m happy
-Aristides

Edit: Made a mistake with the order. Switching to Multithreaded DLL was the solution.

That option doesn’t control whether a DLL is generated as output but rather which version of the C++ runtime library is used: static or DLL. The pre-compiled GLFW static library in the package you downloaded was compiled for Multithreaded DLL and will only work with that setting.

This error means that the GLFW static library file you are using is calling the C++ library function free as if it’s in a DLL but you are then linking the whole application with the static library form (i.e. Multithreaded) of the C++ runtime library instead.

If you want to use Multithreaded for your application you need to download the GLFW source package, configure it with CMake, change the Runtime Library option in Visual Studio to Multithreaded and compile it. Then everything will match.