vendredi 14 juillet 2017

Why am I getting linker errors only for MSVC (VS2015) shared library build?

I am currently developing a simple game engine in c++. In order to have my build process be cross platform I have been using cmake. I have reached the point that I am building the majority of the codebase as a library which my test code links against. This works fine for both static and shared library builds using gcc on linux and also for static library builds using msvc on windows, however for shared library builds using msvc I receive thousands of linker errors.

Some examples of said errors are as follows (this is for a Debug build)

Error   LNK2001 unresolved external symbol __purecall   CuttingEdge 
C:\Projects\Test\CuttingEdge\Build\assimp-vc140-mt.lib(3DSConverter.obj)

Error   LNK2019 unresolved external symbol _malloc referenced in function 
"void * __cdecl operator new(unsigned int)" (??2@YAPAXI@Z)  CuttingEdge 
C:\Projects\Test\CuttingEdge\Build\MSVCRTD.lib(new_scalar.obj)  1

Error   LNK2001 unresolved external symbol ___CxxFrameHandler3  CuttingEdge 
C:\Projects\Test\CuttingEdge\Build\Material.obj 1

Of note, the three places that these errors are occurring: several of the dependencies that my shared library statically links against, the shared library itself, and MSVRTD.lib which I understand to be one of the windows c++ runtime implementations.

From what I understand the missing symbols here are supposed to be provided by the windows c++ runtime, so I assume there is some issue with how my project is linking against that for shared library builds.

Some things I have tried based on information I have found investigating my problem:

  • Ensured that project settings for shared library project and its dependent projects have the same character set setting
  • Ensured that project settings for shared library project and its dependent projects are set to use the same runtime library (/MDd)
  • Ensured that shared library project and its dependant projects are building with the same configuration (Debug)
  • I wasn't previously exporting classes/functions from my shared library using __declspec(dllexport), but have now put this in place, which hasn't made a difference to the linker errors

The problem strikes me as something to do with the build options relating to the windows c++ runtime which seem to be setup by the visual studio cmake generator, which I imagine probably configures these settings correctly.

Aucun commentaire:

Enregistrer un commentaire