# Build issue with dynamic linking on Windows

**URL:** <https://discourse.libcinder.org/t/build-issue-with-dynamic-linking-on-windows/941>\
**Category:** Using Cinder\
**Created:** [November 6, 2017, 2:29pm UTC](https://discourse.libcinder.org/t/build-issue-with-dynamic-linking-on-windows/941 "2017-11-06T14:29:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jibberia](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/jibberia/32/479_2.png) [@jibberia](https://discourse.libcinder.org/u/jibberia)\
**Post date:** [November 6, 2017, 2:29pm UTC](https://discourse.libcinder.org/t/build-issue-with-dynamic-linking-on-windows/941/1 "2017-11-06T14:29:05Z")

</div>

Hello! I’m somewhat new to Cinder, C++, and Windows development, which is making for a fun series of challenges. I’m using VS 2015 on Windows 10.

I have a c++/cuda dependency that must be linked dynamically, so I’m trying to switch my VS project from static to dynamic linking. Cinder is my only other dependency right now. I made these changes:

- Project properties \> C/C++ \> Code Generation \> Runtime Library: Changed `Multi-threaded (/MT)` to `Multi-threaded DLL (/MD)`
- Linker Additional Library Directories: Changed `..\vendor\Cinder\lib\msw\$(PlatformTarget)\$(Configuration)\$(PlatformToolset)\` to `..\vendor\Cinder\lib\msw\$(PlatformTarget)\$(Configuration)_Shared\$(PlatformToolset)\` (in other words, use Release\_Shared instead of Release)
- Opened cinder.sln and built the Release\_Shared target

(I’m only using Release configurations for now.)

The build fails with a few linker errors:

```auto
Error LNK2001 unresolved external symbol "private: static class std::mersenne_twister_engine<unsigned int,32,624,397,31,2567483615,11,4294967295,7,2636928640,15,4022730752,18,1812433253> cinder::Rand::sBase"
(?sBase@Rand@cinder@@0V?$mersenne_twister_engine@I$0CA@$0CHA@$0BIN@$0BP@$0JJAILANP@$0L@$0PPPPPPPP@$06$0JNCMFGIA@$0P@$0OPMGAAAA@$0BC@$0GMAHIJGF@@std@@A)

Error LNK2001 unresolved external symbol "private: static class std::uniform_real_distribution<float> cinder::Rand::sFloatGen" (?sFloatGen@Rand@cinder@@0V?$uniform_real_distribution@M@std@@A)

```

There’s another similar unresolved symbol error for my other dependency, but I don’t think those details are relevant here.

Help of any sort, even vague guesses or clues, would be greatly appreciated!

---

<div class="post-metadata">

**Author:** ![andrewfb](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/andrewfb/32/2_2.png) [@andrewfb](https://discourse.libcinder.org/u/andrewfb)\
**Post date:** [November 7, 2017, 1:39am UTC](https://discourse.libcinder.org/t/build-issue-with-dynamic-linking-on-windows/941/2 "2017-11-07T01:39:14Z")

</div>

Just a quick question, is there anything stopping you from linking against Cinder statically and other libs dynamically? You might have to modify Cinder’s Runtime Library to be `/MD`.

---

<div class="post-metadata">

**Author:** ![jibberia](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/jibberia/32/479_2.png) [@jibberia](https://discourse.libcinder.org/u/jibberia)\
**Post date:** [November 8, 2017, 2:50pm UTC](https://discourse.libcinder.org/t/build-issue-with-dynamic-linking-on-windows/941/3 "2017-11-08T14:50:40Z")

</div>

Nothing except my lack of experience, I suppose… how would I go about doing that?

---

<div class="post-metadata">

**Author:** ![jibberia](https://yyz2.discourse-cdn.com/flex030/user_avatar/discourse.libcinder.org/jibberia/32/479_2.png) [@jibberia](https://discourse.libcinder.org/u/jibberia)\
**Post date:** [November 11, 2017, 12:54pm UTC](https://discourse.libcinder.org/t/build-issue-with-dynamic-linking-on-windows/941/4 "2017-11-11T12:54:23Z")

</div>

FWIW, I’ll tie up this thread. I worked around the linker issue by creating my own implementation of (some of) Cinder’s Rand. This works well enough because my app isn’t making heavy use of random numbers.

Somewhat related: because of the difficulty of making a debug build of one of my dependencies, I’m sticking to Release, with debugging enabled: [https://msdn.microsoft.com/en-us/library/fsk896zz.aspx](https://msdn.microsoft.com/en-us/library/fsk896zz.aspx) Compiler optimization means that sometimes the debugger is wrong, but it’s been an acceptable compromise for my project so far.

Regarding Andrew’s question (thanks for that)… that is something I can try. I think I’d use the Debug or Release configurations (not \_Shared) but use /MD. That might fix the above linker issue.

---

<div class="post-metadata">

**Author:** ![Simon](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@Simon](https://discourse.libcinder.org/u/Simon)\
**Post date:** [November 20, 2017, 3:53pm UTC](https://discourse.libcinder.org/t/build-issue-with-dynamic-linking-on-windows/941/5 "2017-11-20T15:53:18Z")

</div>

I couldn’t reproduce those linker error and have no issue using `ci::Rand` in a shared build.

It seems that you are missing the preprocessor definition `CINDER_SHARED` which turns all `CI_API` into the right import directives. You might want to give it a second shot by following [this small guide](https://github.com/simongeilfus/cinder-runtime#build-cinder-as-a-dll).

If this doesn’t help, it would be interesting to see some code to help reproduce what you’re seeing.
