Linking GLFW with /MT

jonathanhook wrote on Sunday, June 05, 2011:

Hi everyone,

I am trying to link a release build of a project that uses GLFW in VS2010
using the multi-threaded run-time libs (/MT). I’m getting various LNK2005
errors, so somewhere I assume something isn’t linked against /MT. All the
other code I’m linking against I’ve compiled myself using /MT (I’ve double-
double checked!). I’m just using the standard glfw build
(glfw-2.7.bin.WIN32\glfw-2.7.bin.WIN32\lib-msvc100\release\GLFW.lib).

The weird thing is, I’m sure I’ve compiled this whole project (including
GLFW) under /MT. Therefore I was wondering if anyone could confirm whether
GLFW will compile with /MT (as opposed to /MD/MTd etc…) or if anyone else
has had similar problems? Hopefully then I can discount GLFW being the problem
and find what else is wrong!!

Thanks for your help in advance.

Jon

elmindreda wrote on Sunday, June 05, 2011:

There are various issues with the binary package. The safest choice is to
download the source package and build GLFW yourself with appropriate settings.
This way, you can make sure that everything matches.

plmrdoompl wrote on Monday, October 10, 2011:

So I’ve tried that and I get crt0dat.c errors. Is that too covered by building
own glfw library? If so, it’s not helping.

Hi, I have Windows10 system and I’m using Visual Studio 2022.

I have…

  • download glfw-3.3.7 source
  • run CMake-GUI
  • configured without the use of the msvc runtime dll
  • generated the Visual Studio solution/project files
  • used Visual Studio 2022 to build glfw3 in debug, release, and the other builds
  • checked to make sure the Code Generation in the GLFW project was /MT and not /MD

When I link against the resulting library, if I used /MD in my project it builds fine, but if I use /MT I get a slew of unresolved external symbol errors, like this:

1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol strncmp
1>glfw3.lib(context.obj) : error LNK2001: unresolved external symbol strncmp
1>glfw3.lib(egl_context.obj) : error LNK2001: unresolved external symbol strncmp
1>glfw3.lib(osmesa_context.obj) : error LNK2001: unresolved external symbol free
1>glfw3.lib(vulkan.obj) : error LNK2001: unresolved external symbol free
1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol free
1>glfw3.lib(wgl_context.obj) : error LNK2001: unresolved external symbol free
1>glfw3.lib(egl_context.obj) : error LNK2001: unresolved external symbol free
1>glfw3.lib(win32_window.obj) : error LNK2001: unresolved external symbol free
1>glfw3.lib(win32_init.obj) : error LNK2001: unresolved external symbol free
1>glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol free
1>glfw3.lib(monitor.obj) : error LNK2001: unresolved external symbol free
1>glad.obj : error LNK2001: unresolved external symbol free
1>glfw3.lib(window.obj) : error LNK2001: unresolved external symbol free
1>glfw3.lib(init.obj) : error LNK2001: unresolved external symbol free
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol free
1>glad.obj : error LNK2001: unresolved external symbol strstr
1>glfw3.lib(context.obj) : error LNK2001: unresolved external symbol strstr
1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol strstr
1>glad.obj : error LNK2001: unresolved external symbol __stdio_common_vsscanf
1>glfw3.lib(context.obj) : error LNK2001: unresolved external symbol __stdio_common_vsscanf
1>glad.obj : error LNK2001: unresolved external symbol malloc
1>main.obj : error LNK2001: unresolved external symbol __CxxFrameHandler4
1>main.obj : error LNK2001: unresolved external symbol __stdio_common_vfprintf
1>main.obj : error LNK2001: unresolved external symbol __acrt_iob_func
1>main.obj : error LNK2001: unresolved external symbol exit
1>main.obj : error LNK2001: unresolved external symbol __std_terminate
1>TestEvents.obj : error LNK2001: unresolved external symbol “const type_info::`vftable’” (??_7type_info@@6B@)
1>LINK : error LNK2001: unresolved external symbol WinMainCRTStartup
1>glfw3.lib(window.obj) : error LNK2001: unresolved external symbol strncpy
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol strncpy
1>glfw3.lib(monitor.obj) : error LNK2001: unresolved external symbol strncpy
1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol strncpy
1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol calloc
1>glfw3.lib(wgl_context.obj) : error LNK2001: unresolved external symbol calloc
1>glfw3.lib(egl_context.obj) : error LNK2001: unresolved external symbol calloc
1>glfw3.lib(osmesa_context.obj) : error LNK2001: unresolved external symbol calloc
1>glfw3.lib(win32_init.obj) : error LNK2001: unresolved external symbol calloc
1>glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol calloc
1>glfw3.lib(monitor.obj) : error LNK2001: unresolved external symbol calloc
1>glfw3.lib(vulkan.obj) : error LNK2001: unresolved external symbol calloc
1>glfw3.lib(window.obj) : error LNK2001: unresolved external symbol calloc
1>glfw3.lib(init.obj) : error LNK2001: unresolved external symbol calloc
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol calloc
1>glfw3.lib(win32_window.obj) : error LNK2001: unresolved external symbol calloc
1>glfw3.lib(wgl_context.obj) : error LNK2001: unresolved external symbol __GSHandlerCheck
1>glfw3.lib(egl_context.obj) : error LNK2001: unresolved external symbol __GSHandlerCheck
1>glfw3.lib(osmesa_context.obj) : error LNK2001: unresolved external symbol __GSHandlerCheck
1>glfw3.lib(win32_window.obj) : error LNK2001: unresolved external symbol __GSHandlerCheck
1>glfw3.lib(win32_init.obj) : error LNK2001: unresolved external symbol __GSHandlerCheck
1>glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol __GSHandlerCheck
1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol __GSHandlerCheck
1>glfw3.lib(window.obj) : error LNK2001: unresolved external symbol __GSHandlerCheck
1>glfw3.lib(init.obj) : error LNK2001: unresolved external symbol __GSHandlerCheck
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __GSHandlerCheck
1>glfw3.lib(context.obj) : error LNK2001: unresolved external symbol __GSHandlerCheck
1>glfw3.lib(wgl_context.obj) : error LNK2001: unresolved external symbol __security_check_cookie
1>glfw3.lib(egl_context.obj) : error LNK2001: unresolved external symbol __security_check_cookie
1>glfw3.lib(osmesa_context.obj) : error LNK2001: unresolved external symbol __security_check_cookie
1>glfw3.lib(win32_window.obj) : error LNK2001: unresolved external symbol __security_check_cookie
1>glfw3.lib(win32_init.obj) : error LNK2001: unresolved external symbol __security_check_cookie
1>glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol __security_check_cookie
1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol __security_check_cookie
1>glfw3.lib(window.obj) : error LNK2001: unresolved external symbol __security_check_cookie
1>glfw3.lib(init.obj) : error LNK2001: unresolved external symbol __security_check_cookie
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __security_check_cookie
1>glfw3.lib(context.obj) : error LNK2001: unresolved external symbol __security_check_cookie
1>glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol memset
1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol memset
1>glfw3.lib(window.obj) : error LNK2001: unresolved external symbol memset
1>glfw3.lib(init.obj) : error LNK2001: unresolved external symbol memset
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol memset
1>glfw3.lib(win32_init.obj) : error LNK2001: unresolved external symbol memset
1>glfw3.lib(wgl_context.obj) : error LNK2001: unresolved external symbol __security_cookie
1>glfw3.lib(egl_context.obj) : error LNK2001: unresolved external symbol __security_cookie
1>glfw3.lib(osmesa_context.obj) : error LNK2001: unresolved external symbol __security_cookie
1>glfw3.lib(win32_window.obj) : error LNK2001: unresolved external symbol __security_cookie
1>glfw3.lib(win32_init.obj) : error LNK2001: unresolved external symbol __security_cookie
1>glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol __security_cookie
1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol __security_cookie
1>glfw3.lib(window.obj) : error LNK2001: unresolved external symbol __security_cookie
1>glfw3.lib(init.obj) : error LNK2001: unresolved external symbol __security_cookie
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __security_cookie
1>glfw3.lib(context.obj) : error LNK2001: unresolved external symbol __security_cookie
1>glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol _fltused
1>glfw3.lib(monitor.obj) : error LNK2001: unresolved external symbol _fltused
1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol _fltused
1>glfw3.lib(window.obj) : error LNK2001: unresolved external symbol _fltused
1>glfw3.lib(init.obj) : error LNK2001: unresolved external symbol _fltused
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol _fltused
1>glfw3.lib(win32_window.obj) : error LNK2001: unresolved external symbol _fltused
1>glfw3.lib(init.obj) : error LNK2001: unresolved external symbol __stdio_common_vsprintf
1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol __stdio_common_vsprintf
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol strcspn
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol strspn
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol realloc
1>glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol realloc
1>glfw3.lib(monitor.obj) : error LNK2001: unresolved external symbol realloc
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol strtoul
1>glfw3.lib(input.obj) : error LNK2001: unresolved external symbol memcpy
1>glfw3.lib(win32_monitor.obj) : error LNK2001: unresolved external symbol memcpy
1>glfw3.lib(monitor.obj) : error LNK2001: unresolved external symbol qsort
1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol qsort
1>glfw3.lib(monitor.obj) : error LNK2001: unresolved external symbol memmove
1>glfw3.lib(monitor.obj) : error LNK2001: unresolved external symbol powf
1>glfw3.lib(vulkan.obj) : error LNK2001: unresolved external symbol strcmp
1>glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol strcmp

What am I missing / doing wrong?

Thanks for any help!

Hi @Shavais,

Welcome to the GFLW forum.

On CMake 3.15 and later you can set the standard CMake
CMAKE_MSVC_RUNTIME_LIBRARY variable instead of this GLFW-specific option - is this what you set?

If you have got /MT properly set in the library build are you then linking to that library when building your library? I can’t thinking of why this wouldn’t work if you have confirmed you are linking with /MT.

You can check if the library is built with /MD by using a dependencies walker like:

Binaries are on the releases page: Releases · lucasg/Dependencies · GitHub and you can run DependenciesGui.exe and then drag the library onto the window to see the libraries it uses.

If you see VCRUNTIME140.DLL (or similar depending on the platform toolset you are using) then you have linked with /MD.

Hi, thanks for your reply! Somehow, while I’ve been getting GLFW emails for a while, now, I missed the notification about it until now. I tried, at the time, to make sure I was building against the correct library, but it occurs to me now that I may not have manually deleted all the potentials and then rerun the build with /MT to make sure the only potentials would be built with /MT. Anyway, I gave up trying to get /MT to work and I’ve just been using /MDd and /MD for the moment. But I’d prefer not to ship the .dll alongside my program, so, at some point I’ll have to dedicate some time to trying again to troubleshooting this. I’ll look for where you set that CMake variable. Anyway thanks again and when I eventually get back to this I’ll try to find and update this thread.