3

I created simple Windows Runtime Component using Visual Studio template. By default project is dynamically linked to C/C++ Runtime Library with MD/MDd option.

When I change it into MT/MTd (Project properties -> C/C++ -> Code Generation -> Runtime Library) and build the project I am getting error

1>C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.CppBuild.targets(1693,5): error MSB8024: Using static version of the C++ runtime library is not supported.

How can I compile Windows Runtime Component with MTd option? I need this since WinRT Component will refer other 3rd part library which is built with statically linked C++ runtime library.

miradham
  • 2,285
  • 16
  • 26
  • The error message is quite explicit, there is no magic button you can push to make it disappear. Having to rebuild a library to match the compiler version and settings is entirely normal. If it is not yours then ask the owner for a rebuild. And keep in mind that such a library is unlikely to work at all in a UWP app, verifying it with WACK is essential. – Hans Passant Dec 19 '17 at 12:02
  • 1
    The solution is to request a version of the 3rd party library that dynamically links against the same CRT you are using in your component. – IInspectable Dec 19 '17 at 15:44

1 Answers1

1

Unfortunately you can't avoid the restriction.

But I have doubts about "I need this since WinRT Component will refer other 3rd part library which is built with statically linked C++ runtime library". Did you try to use that 3rd part library? You should have no problems adding it to your project.

Anton Malyshev
  • 8,686
  • 2
  • 27
  • 45
  • I can use 3rd party lib only after recompile with MD flag, otherwise I am getting compile error. Btw, do you know if there is a specific reason to add such restriction? – miradham Dec 19 '17 at 14:18
  • .NET Framework needs it for some reason. Also look at the https://stackoverflow.com/questions/564872/link-libraries-with-dependencies-in-visual-c-without-getting-lnk4006 – Anton Malyshev Dec 19 '17 at 14:21
  • @miradham: Statically linking against the CRT imposes undue restrictions. See [Potential Errors Passing CRT Objects Across DLL Boundaries](https://learn.microsoft.com/en-us/cpp/c-runtime-library/potential-errors-passing-crt-objects-across-dll-boundaries) for details, why you always want to dynamically link against the CRT. And always link against the same CRT. – IInspectable Dec 19 '17 at 15:42
  • or just don't pass CRT objects across DLL boundaries ;) – Anton Malyshev Dec 19 '17 at 15:50
  • This isn't something you have any control over. It's the 3rd party library that made the decision already. You cannot change that after the fact. – IInspectable Dec 19 '17 at 18:16
  • Yes, but most libraries use C-style interfaces for the reason – Anton Malyshev Dec 19 '17 at 20:14