# Could not link with glfw on windows

**URL:** <https://discourse.glfw.org/t/could-not-link-with-glfw-on-windows/1584>\
**Category:** support\
**Created:** [June 12, 2020, 10:21am UTC](https://discourse.glfw.org/t/could-not-link-with-glfw-on-windows/1584 "2020-06-12T10:21:34Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nickpofig](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@Nickpofig](https://discourse.glfw.org/u/Nickpofig)\
**Post date:** [June 12, 2020, 10:21am UTC](https://discourse.glfw.org/t/could-not-link-with-glfw-on-windows/1584/1 "2020-06-12T10:21:34Z")

</div>

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(b_st_rds).

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.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [June 12, 2020, 10:48am UTC](https://discourse.glfw.org/t/could-not-link-with-glfw-on-windows/1584/2 "2020-06-12T10:48:18Z")

</div>

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:

> **[Linker Tools Warning LNK4098](https://learn.microsoft.com/en-us/cpp/error-messages/tool-errors/linker-tools-warning-lnk4098?view=msvc-170&viewFallbackFrom=vs-2019)**
>
> Describes how incompatible libraries cause linker tools warning LNK4098, and how to use /NODEFAULTLIB to fix it.

and forum post answer:

> [@Setting Up GLFW on Visual Studio](https://discourse.glfw.org/t/setting-up-glfw-on-visual-studio/1344/4):
>
> 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. Multithr…

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:

> **[GitHub - juliettef/GLFW-CMake-starter: Use CMake to create a project with GLFW...](https://github.com/juliettef/GLFW-CMake-starter)**
>
> Use CMake to create a project with GLFW - Multi-platform Windows, Linux and MacOS. - GitHub - juliettef/GLFW-CMake-starter: Use CMake to create a project with GLFW - Multi-platform Windows, Linux a...

---

<div class="post-metadata">

**Author:** ![Nickpofig](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@Nickpofig](https://discourse.glfw.org/u/Nickpofig)\
**Post date:** [June 12, 2020, 1:18pm UTC](https://discourse.glfw.org/t/could-not-link-with-glfw-on-windows/1584/3 "2020-06-12T13:18:18Z")

</div>

Thank you for the reply 🙂

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.

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [June 12, 2020, 2:02pm UTC](https://discourse.glfw.org/t/could-not-link-with-glfw-on-windows/1584/4 "2020-06-12T14:02:00Z")

</div>

> [@Nickpofig](#):
>
> what cmake command should I run in order to generate correct visual studio project settings

Take a look at the example I linked to [GLFW-CMake-starter](https://github.com/juliettef/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](https://docs.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library?view=vs-2019). 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.

> [@Nickpofig](#):
>
> 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’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.

---

<div class="post-metadata">

**Author:** ![Nickpofig](https://avatars.discourse-cdn.com/v4/letter/n/54ee81/32.png) [@Nickpofig](https://discourse.glfw.org/u/Nickpofig)\
**Post date:** [June 12, 2020, 2:21pm UTC](https://discourse.glfw.org/t/could-not-link-with-glfw-on-windows/1584/5 "2020-06-12T14:21:50Z")

</div>

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 😅

---

<div class="post-metadata">

**Author:** ![felix102](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@felix102](https://discourse.glfw.org/u/felix102)\
**Post date:** [August 21, 2020, 4:14pm UTC](https://discourse.glfw.org/t/could-not-link-with-glfw-on-windows/1584/6 "2020-08-21T16:14:02Z")

</div>

I’m having the exact same problem. I’m embeding a GLFW window into a MFC application (using VS2019). I’ve tried changing the runtime library to MultiThreaded. No luck, I’m still getting the following. Any advice would be appreciated.

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\>MSVCRT.lib(chandler4gs.obj) : error LNK2019: unresolved external symbol \_\_except\_handler4\_common referenced in function \_\_except\_handler4

---

<div class="post-metadata">

**Author:** ![dougbinks](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.glfw.org/dougbinks/32/39_2.png) [@dougbinks](https://discourse.glfw.org/u/dougbinks)\
**Post date:** [August 21, 2020, 6:01pm UTC](https://discourse.glfw.org/t/could-not-link-with-glfw-on-windows/1584/7 "2020-08-21T18:01:13Z")

</div>

Hi @felix102 welcome to the GLFW forum!

See the comment from above:

> [@dougbinks](#):
>
> 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.

So your project `properties->C/C++->Code Generation->Runtime Library` should be `Multi-threaded DLL (/MD)` in Release and `Multi-threaded Debug DLL (/MDd)` in debug.

Does this help? If not check out the project below:

> **[GitHub - juliettef/GLFW-CMake-starter: Use CMake to create a project with GLFW...](https://github.com/juliettef/GLFW-CMake-starter)**
>
> Use CMake to create a project with GLFW - Multi-platform Windows, Linux and MacOS. - GitHub - juliettef/GLFW-CMake-starter: Use CMake to create a project with GLFW - Multi-platform Windows, Linux a...

If you get that project building you can compare the configuration properties pages against your project to find out what the difference is.

---

<div class="post-metadata">

**Author:** ![felix102](https://avatars.discourse-cdn.com/v4/letter/f/a88e4f/32.png) [@felix102](https://discourse.glfw.org/u/felix102)\
**Post date:** [August 21, 2020, 8:31pm UTC](https://discourse.glfw.org/t/could-not-link-with-glfw-on-windows/1584/8 "2020-08-21T20:31:41Z")

</div>

Thanks! that solved the problem. I guess I only looked at the user’s solution. I should read everything next time!
