1

I need to link SDL2 statically in a DLL, but I'm having this error: LNK2019: unresolved external symbol __imp___acrt_iob_func referenced in function "void __cdecl `dynamic initializer for '__iob_func''(void)" (??__E__iob_func@@YAXXZ)

The strange part is that when I build an .exe, it all works fine, but when I change the configuration type to .dll it doesn't. I found the following question: unresolved external symbol __imp__fprintf and __imp____iob_func, SDL2 which looks like a duplicate, but not only I am building everything with the same compiler (VS2017), but I'm also not having problems if I don't link it statically.

I've tried the solutions there (rebuilding is N/A, adding definitions, and including legacy_stdio_definitions.lib) to no avail. I can only assume that the problem is in the code I'm linking statically (since the static build contains everything).

If somebody wants to reproduce, it's simple, you just have to build SDL-static and include the library in a DLL project. If you include SDL2.lib (dynamic) it works, if you include SDL2-static.lib in an .exe project it works too.

PS: I'm using the same SDK and toolset to compile both SDL and the DLL that links it statically. I've rebuilt everything for each solution I tried.

Alan
  • 33
  • 5
  • Evidently the static build of SDL2 you use link the Microsoft runtime library dynamically. – Cheers and hth. - Alf Sep 17 '18 at 05:41
  • @Cheersandhth.-Alf thank you. That wasn't too evident to me, but your comment was spot-on. Unfortunately I can't give you any kind of reputation points apparently, so please accept my gratitude :). – Alan Sep 17 '18 at 13:25

1 Answers1

0

In order to compile a DLL in VS2017 that links SDL statically you have to link some definitions that are a bit scaterred.

Besides of course the imm32, winmm and version libraries that SDL2 uses, if you're building a DLL you also have to include the msvcrt also the vcruntime and ucrt.

Alan
  • 33
  • 5