Could not link with glfw on windows

I am trying to link basic glfw example(which you could find on GettingStarted page) using clang++(yes, I have written example in the c++) by providing link commands in the terminal (without any IDE or build systems). My problem is following linker errors:


glfw3.lib(window.obj) : error LNK2019: unresolved external symbol __imp_strncpy referenced in function glfwWindowHintString
glfw3.lib(input.obj) : error LNK2001: unresolved external symbol __imp_strncpy
glfw3.lib(win32_joystick.obj) : error LNK2001: unresolved external symbol __imp_strncpy
glfw3.lib(context.obj) : error LNK2019: unresolved external symbol __imp___stdio_common_vsscanf referenced in function sscanf
glfw3.lib(input.obj) : error LNK2019: unresolved external symbol __imp_strspn referenced in function glfwUpdateGamepadMappings


it is basically 3 missing implementations of external functions: strncpy, _stdio_common_vsscanf, strspn; as I understand they all belongs to Windows CRT library, but inlcuding [ libucrt.lib ] or [ ucrt.lib ] does NOT solve this problem (but makes everything even worse). I am not sure does libucrt.lib and ucrt.lib inplements this functions, because microsoft itself does not explicitly specify those functions library in the documentation(bstrds).

Btw, already included libraries are: glfw3 opengl32 user32 gdi32 shell32 kernel32; as I understand this is a default set to build program using glfw on windows platform.

I would appreciate if you help me to solve this problem - I have run out of ides.

P.S I link with glfw.lib, which has been compiled in VS2019 without any cmake options or changes - the only action I did was setting up Release mode, x64 target platform mode, and building glfw ONLY.
I wish I could build things without Cmake and Visual Studio, but hey - it is a world where we live.

Is this the full list of warnings and errors from the linking, or do you also see LNK4098 or LNK4286 warnings?

It could be that you have compiled GLFW with one run-time library and are linking with another. See:

and forum post answer:

Using Clang to compile on Windows via the command line is fairly advanced. If you want to get up and running quickly with a basic example try:

Thank you for the reply :slight_smile:

I have those warnings(LNK4098, LNK4286) alongside with LNK4217 warrning, as I understand you are telling me that I am linking with incorrect version of GLFW static library build, if it so - what cmake command should I run in order to generate correct visual studio project settings. I am confused with Multithreaded and Multithreaded DLL terminology; It is hard to see what compiles as static library with holes for dynamicly linked libraries or static library with everything included inside of it.

I suppose, in my case I need to build static glfw library with holes for dynamically linked C++ standard libraries (as they supposed to be linked automatically by Windows OS on the program launch, if I get it right). I also thought the default glfw visual studio build setting was that type of static library(with holes for opengl and other libraries).

If it possible I would like to avoid third party solutions like the one you advised to keep level of complexity on the reasonable level. I don’t want to depend on things that I could do by myself, because my final goal is a stable and independent product like render engine or game engine.

Take a look at the example I linked to GLFW-CMake-starter for a simple cmake project. You can use this to learn how to use cmake with GLFW.

The basic issue is you need to set all linked projects to use the same Runtime Library. By default GLFW with cmake will build with /MD in release and /MDd in debug so if you use those in your own project then you should be able to resolve your issues.

I’m not sure what you mean by third party solution but it’s always useful to use a known working solution first before experimenting with alternative setups.

Thank you for your help,
indeed, the issue was in GLFW build options for visual studio(mircosoft cl compiler), I have added /MT option to specifically tell compiler to use the multithread, static version of the run-time library (still don’t know exactly what does it mean). I guess, in that build version dll “holes” for windows standrad library has been included in GLFW static library file, which resolved the missing external symbols problem.
Hope, now, everything would work as expected :sweat_smile: