Search code examples
cmakeshared-librariesstatic-librarieslinker-errorsassimp

how to build assimp as a static lib (/MT)?


I've been trying to build assimp as a static library using CMakeGUI. I got assimp-3.1.1 for the source code. build location at assimp-3.1.1/build. I got 2 options which appear to be relevant: ASSIMP_BUILD_STATIC_LIB and BUILD_SHARED_LIBS. In my attempt to build a static lib I enabled the first and disabled the second. I clicked configure again and generated the solution. In the solution I clicked 'Build Solution'. Then in assimp-3.1.1/build/code/Debug I found the assimpd.lib file which should be in /MT. But it's not. When I link it in my project I get linker errors like

Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MDd_DynamicDebug' doesn't match value >'MTd_StaticDebug' in main.obj Mush3D C:\VSProjects\Mush3D\Mush3D\assimpd.lib(Importer.obj) 1

in the assimpd.lib file. So the lib is in MDd (my project is in MTd). In the command prompt for VS22 I entered "dumpbin /directives "C:\assimp-3.1.1\build\code\Debug\assimpd.lib" " to see its version and found the following:

Linker Directives


/FAILIFMISMATCH:_CRT_STDIO_ISO_WIDE_SPECIFIERS=0 /FAILIFMISMATCH:_MSC_VER=1900 /FAILIFMISMATCH:_ITERATOR_DEBUG_LEVEL=2 /FAILIFMISMATCH:RuntimeLibrary=MDd_DynamicDebug /DEFAULTLIB:msvcprtd /FAILIFMISMATCH:annotate_vector=0 /FAILIFMISMATCH:annotate_string=0 /DEFAULTLIB:MSVCRTD /DEFAULTLIB:OLDNAMES

note that the DEFAULTLIBs msvcprtd and MSVCRTD are also /MDd.

I think the /FAILIFMISMATCH might be responsible. I can't find it in the assimp solution, the CMakeList in assimp-3.1.1, or the CMakeCache in assimp-3.1.1/build

I don't know where else to look for /FAILIFMISMATCH to change them (if changing them is the solution). If the /FAILIFMISMATCH lines aren't responsible for my lib being built as MDd, what else could it be? Is there another setting I missed? I can't change it for the entire solution through the solution properties page.

Should I just give up building assimp as a static lib? Due to some mismatches between 3 libs I used I decided to build some of them again and chose /MT (my bullet physics libs were already in /MT), but maybe switching the other 2 to /MD will be easier than getting assimp in /MT...

Edit: It appears building the Bullet physics libs in /MD is not something Bullet support, and thus for me practically impossible... so if Bullet likes being static and assimp likes being dynamic, what should I do?


Solution

  • To build assimp as a static library you need to switch to the latest version 5.2.5 or the latest master. Get the source, go to the root of the repo / source and use cmake to generate the project files:

    cmake CMakeLists.txt -dBUILD_SHARED_LIBS=OFF
    

    Now you shall be able to build the static library.