I am trying to statically link my program with spdlog.
I have built spdlog from source using the Debug configuration, and I have specifically cleared the "Runtime Library" setting to avoid any CRT incompatibilities with my project.
However, when I try to build my program (also using the Debug configuration), I get a bunch of errors:
Warning LNK4098 defaultlib 'LIBCMT' conflicts with use of other libs; use /NODEFAULTLIB:library
Error LNK2038 mismatch detected for '_ITERATOR_DEBUG_LEVEL': value '0' doesn't match value '2' in cmake_pch.obj
Error LNK2038 mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' doesn't match value 'MDd_DynamicDebug' in cmake_pch.obj
All my research suggests that this error indicates a mismatched CRT between the library and my program. In the past I have been able to fix this same error by clearing the "Runtime Library" property of the library, but in this case that does not seem to be helping.
What am I missing here?
A static library that uses features of the standard library requires a Runtime Library. This answer suggests otherwise, but I have not yet found any other sources to validate this.
To avoid errors, it is important that all libraries used by an application share the same Runtime Library.
In this case, the static library in question should be built with the Multi-threaded Debug DLL (/MDd)
or Multi-threaded DLL (/MD)
runtime. It is not a problem for a static library to use a DLL runtime.
Note that some libraries such as GLEW do not use the C runtime library, so it does not matter which runtime they are built with. Other libraries may be more restrictive. In any case, the same setting should be used by all libraries within an application.