Link external static lib along with dynamic libs to the executable


Can’t understand why linker gives me error:

licensecc_static.lib(licensecc.obj) : error LNK2038: mismatch detected for 'RuntimeLibrary': value 'MT_StaticRelease' d
oesn't match value 'MD_DynamicRelease' in Main.obj

I externally compiler licensecc_static.lib as static library and I’m trying to link it to executable.
Also I link few shared libs to the same executable.

I tried to:

  set_property(TARGET licensecc::licensecc_static PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

but this didn’t help.

All of them compiled in Release mode with MSVC 2022

The runtime of all objects (including those from libs) must match.
Currently you’re compiling your library against the static and Main.obj against the DLL runtime. Both in release, not debug mode.
The manual of MSVC_RUNTIME_LIBRARY shows all 4 possible values.

1 Like

Thank you for the explanation.

It seems I don’t understand something.
For now I just compiled licensecc library without -DSTATIC_RUNTIME=1 even though it is recommended to set it to 1. It works if it is 0 (no mentionned errors).

But what STATIC_RUNTIME really changes?
As I see if I pass STATIC_RUNTIME=1 then /MT flag is added (link for the code).
Why adding /MT flag leads to mentionned error: after all the library is added using ADD_LIBRARY(licensecc_static STATIC ${sources}) - it is still static.

The type of the MSVC runtime is unrelated to the type of library you want to build. It’s totally possible to use the static runtime with a DLL, or the dynamic runtime with a static library.

1 Like

Thank you! I will try to google that.
I think I have lack of knowledge there.