0

I am trying to link static and dynamic libraries in the same project in visual studio 2019. The thing is:

  • In project properties -> C/C++ -> Code Generation, when I select MT for Runtime library, my dynamic library creates a problem mismatch detected for runtimeLibrary: value MD_DynamicRelease doesn't match value MT_StaticRelease.
  • In project properties -> C/C++ -> Code Generation, when I select MD for Runtime library, my static library creates the same problem

I have read other posts like Linking with both static and dynamic libraries in MSVC but there is no explanation on how to link both statically and dynamically in the project. Could you please explain me how I can proceed?

froz
  • 163
  • 1
  • 12
  • 1
    You will need to create 2 new configurations (for total of 4). And set the runtime library and debug/release options in each one. So you will end up with 4 builds in total /MTd, /MT, /MDd, /MD, etc. – Richard Critten Jul 03 '19 at 16:15
  • How can I do this? – froz Jul 03 '19 at 16:18
  • 1
    `Build > Configuration Manager ...` Open the Active solution configurations dropdown and click `` fill in the configuration details. – Richard Critten Jul 03 '19 at 16:25
  • But at then end, I want only one .exe in release. What you propose is to make two different builds. My goal is, in one executable to have some libraries that are dynamically linked and other that are statically linked? – froz Jul 03 '19 at 16:29
  • 2
    Why are you trying to link with both the static and dynamic runtime libraries? You need to choose one or the other. – 1201ProgramAlarm Jul 03 '19 at 16:30
  • Because I have some libraries that can only be linked dynamically, for legal reasons and other that I have to link statically – froz Jul 03 '19 at 16:31
  • 2
    You can't mix both in the same build, as you will get multiple instances of the runtime support library. – Richard Critten Jul 03 '19 at 16:33
  • Arf... Is it specific to visual studio? In QT creator, it is possible – froz Jul 03 '19 at 16:34
  • 1
    It is undefined behavior to mix and match runtimes on windows. Your program may appear to work but end up crashing or randomly giving you the wrong result. – drescherjm Jul 03 '19 at 16:35

0 Answers0