Visual Studio 2015 Run-Time Dependencies or How to Get Rid of Universal Crt

Visual studio 2015 run-time dependencies or how to get rid of Universal CRT?

(Updated 11.10.2016).

It's possible to get rid of universal CRT by linking it statically, I'll get to it later on, but let's take
a look if you continue to use universal CRT as such.

According to article https://blogs.msdn.microsoft.com/vcblog/2015/03/03/introducing-the-universal-crt/ -
it's possible to launch your application using universal crt dll distributables from following folder:
C:\Program Files (x86)\Windows Kits\10\Redist\ucrt

There are 41 files totally in list with 1.8 Mb size in total. (example for 64-bit platform)

Of course it's not enough, you will need additionally vcruntime140.dll & msvcp140.dll coming from following folder:
C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist\x64\Microsoft.VC140.CRT

So after that you will ship totally 43 additional dll's besides your application.

It's also possible to statically compile ucrt library inside your application after which you will not need 43 dll's -
but whether static link will for after linking or not - depends on your application - how many dll's and which api's are in use.
Generally after ucrt gets linked into two different dll's they don't necessarily share same globals with each other - which can results in errors.

You need to link against vcruntime.lib / msvcrt.lib, but it's not sufficient - there are extra _VCRTIMP= and _ACRTIMP=
defines which needs to be disabled from pulling functions from ucrt.

If you're using premake5 you can configure your project like this:

defines { "_VCRTIMP="}
linkoptions { "/nodefaultlib:vcruntime.lib" }
links { "libvcruntime.lib" }

followed by:

defines { "_ACRTIMP="}
linkoptions { "/nodefaultlib:msvcrt.lib" }
links { "libcmt.lib" }

Defines are not documented by Microsoft - so it's possible that it's subject to change in future.

Besides your own projects, you will need to re-compile all static libraries which are in use in your projects.

As for boost libraries - I've managed to compile boost as well, using b2.exe boostrapper

boost>call b2 threading=multi toolset=msvc-14.0 address-model=64 --stagedir=release_64bit --build-dir=intermediate_64but release link=static,shared --with-atomic --with-thread --with-date_time --with-filesystem define=_VCRTIMP= define=_ACRTIMP=

When troubleshooting linking problems - notice that unresolved __imp* function names from because of dllimport keyword usage -
and if you link against libvcruntime.lib, you should not have any __imp* references.

Upgrading to Universal CRT-how can I get rid of a dependency on vcruntime140.dll and msvcp140.dll?

I've done some more digging, and found this page that says the following:

Starting in Visual Studio 2015, the CRT has been refactored into new
binaries. The Universal CRT (UCRT) contains the functions and globals
exported by the standard C99 CRT library. The UCRT is now a Windows
component, and ships as part of Windows 10.

Great, that's what I expected. Just below though is this:

The vcruntime library contains Visual C++ CRT implementation-specific
code, such as exception handling and debugging support, runtime checks
and type information, implementation details and certain extended
library functions. This library is specific to the version of the
compiler used.

Which implies that there is still a non-universal VC++ dependency that gets linked in by VS. To me, this implies that a dependency-free DLL doesn't really exist (at least not something built with VC++), since you'll always have a vcruntime dependency.

There is always the option of static linking (/MT), but in my case, I'm also looking at a DLL that has /clr, and the two options are mutually exclusive. Application local deployment (just copy vcruntime140.dll with the binaries) also seems to work, and may be the best option for something that I want to be a portable/xcopy deployment.

I'm going to mark this as an answer for now, but if there's a way around this, I'd be interested in seeing it.

How to I update my C++ project in Visual Studio 2015 to use the new Universal CRT?

When you convert your project, you need to make sure you update both the includes AND the linker settings to point to the new CRT.

For includes, add the following:

$(UniversalCRT_IncludePath)

For link, add one of the following depending on your target processor:

$(UniversalCRT_LibraryPath_x86)
$(UniversalCRT_LibraryPath_x64)
$(UniversalCRT_LibraryPath_arm)

Running a Visual Studio 2015 C++ Executable Without Installing the Visual C++ Redistributable Packages

This was surprisingly not closed as a duplicate. And I hate leaving open questions unanswered. So I'll answer it myself by saying that codestation's comment links to this question which links to this article which describes how to do this in the section that starts with bold red text.

You shouldn't upvote this. Upvote the answer in the linked question.



Related Topics



Leave a reply



Submit