Visual studio 2015运行时依赖或如何摆脱Universal CRT? [英] Visual studio 2015 run-time dependencies or how to get rid of Universal CRT?

查看:3487
本文介绍了Visual studio 2015运行时依赖或如何摆脱Universal CRT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用visual studio 2015编译的.dll的几个,并尝试部署在一些较旧的Windows 7/64位。试图猜测哪些dll是应用程序需要启动和复制MSVCP140.DLL& VCRUNTIME140.DLL - 但应用程序无法加载vs2015 dll。开始分析什么是错误 - 依赖者步行者显示了以下dll的依赖关系:

  API-MS-WIN-CRT- L1-1-0.DLL 
API-MS-WIN-CRT-HEAP-L1-1-0.DLL
API-MS-WIN-CRT-CONVERT-L1-1-0.DLL
API-MS-WIN-CRT-STRING-L1-1-0.DLL
API-MS-WIN-CRT-STDIO-L1-1-0.DLL
API-MS- -CRT-RUNTIME-L1-1-0.DLL
API-MS-WIN-CRT-FILESYSTEM-L1-1-0.DLL
API-MS-WIN-CRT-TIME-L1-1 -0.DLL

这是特别令人惊讶的,因为我最好的了解CRT负责启动dll / exe ,它不提供任何更高级别的服务。



好,试图找出如何摆脱它们或至少最小化。



找到一篇文章:
https://blogs.msdn.microsoft.com/vcblog/2015/03/03/introducing-the-universal-crt/



它提到释放静态库 - 所以我想我可以链接他们,摆脱* L1-1-0.DLL *依赖地狱,但无论我试过 - 我没有成功。我试图链接到libvcruntime.lib,libucrt.lib,libcmt.lib,试图禁用使用链接器选项/nodefaultlib:vcruntime.lib,甚至试图添加包括目录$(UniversalCRT_IncludePath),并且覆盖一些



作为一个中间解决方案,我回到使用Visual studio 2013,其中CRT dll只有两个:msvcp120.dll,msvcr120.dll。



当然,你可能会建议安装Visual studio 2015运行时,但我们的一个要求是支持



你可以推荐我别的东西,而不是等待Visual studio 2017到达? / p>

解决方案

(Updated 11.10.2016)。



删除通用CRT通过链接它静态,我会得到它以后,但让我们采取
a看,如果你继续使用通用CRT这样。



根据文章 https://blogs.msdn.microsoft.com/vcblog/2015/03/03/introducing-the-universal-crt/ -
可以启动您的应用程序使用通用crt dll可分发从以下文件夹:
C:\Program文件(x86)\Windows Kits \10\Redist\ucrt



总共有41个文件,共1.8 MB。 (64位平台的示例)



当然这还不够,您还需要额外的vcruntime140.dll和amp; msvcp140.dll来自以下文件夹:
C:\Program文件(x86)\Microsoft Visual Studio 14.0 \VC\redist\x64 \Microsoft.VC140.CRT



因此,除了您的申请之外,您还将发送43个额外的dll。



也可以在你的应用程序中静态编译ucrt库,之后你不需要43 dll的 -
,但是链接后是否静态链接将取决于你的应用程序 - 多少dll和哪些api的使用。
通常在ucrt链接到两个不同的dll之后,它们不一定会彼此共享相同的全局变量 - 这可能会导致错误。



对vcruntime.lib / msvcrt.lib,但它不够 - 有额外的 _VCRTIMP = _ACRTIMP =
定义哪些需要禁用从ucrt中拉取函数。



如果你使用premake5,你可以这样配置项目:

 定义{_VCRTIMP =} 
linkoptions {/nodefaultlib:vcruntime.lib}
links {libvcruntime.lib }

后接:

 定义{_ACRTIMP =} 
linkoptions {/nodefaultlib:msvcrt.lib}
links {libcmt.lib}


除了你自己的项目,你将需要重新编译在你的项目中使用的所有静态库。



至于boost库 - 我管理使用b2.exe boostrapper



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



在解决链接问题时,请注意未解决的 __ imp * 函数名,因为 dllimport 关键字使用 -
如果你链接到libvcruntime.lib,你不应该有任何 __ imp * 引用。


Compiled couple of .dll's using visual studio 2015, and tried to deploy on some older windows 7 / 64 bit. Tried also to guess which dll's are needed for application to start and copied MSVCP140.DLL & VCRUNTIME140.DLL - but application could not load vs2015 dll. Started to analyze what is wrong - and dependency walker showed dependencies from following dll's:

API-MS-WIN-CRT-MATH-L1-1-0.DLL
API-MS-WIN-CRT-HEAP-L1-1-0.DLL
API-MS-WIN-CRT-CONVERT-L1-1-0.DLL
API-MS-WIN-CRT-STRING-L1-1-0.DLL
API-MS-WIN-CRT-STDIO-L1-1-0.DLL
API-MS-WIN-CRT-RUNTIME-L1-1-0.DLL
API-MS-WIN-CRT-FILESYSTEM-L1-1-0.DLL
API-MS-WIN-CRT-TIME-L1-1-0.DLL

This was especially surprising since to my best understanding CRT is responsible for starting dll/exe, it does not provide any higher level services.

Ok, tried to figure out how to get rid of them or at least to minimize.

Found one article: https://blogs.msdn.microsoft.com/vcblog/2015/03/03/introducing-the-universal-crt/

It mentions about release static libraries - so I thought that I could link against them and get rid from *L1-1-0.DLL* dependency hell, but no matter what I have tried - I had no success. I've tried to link against libvcruntime.lib, libucrt.lib, libcmt.lib, tried to disable using linker option "/nodefaultlib:vcruntime.lib", and even tried to add include directory $(UniversalCRT_IncludePath), and also overriding some of define's as I have tried to guess they works - none of my attempts helped.

As an intermediate solution I've fall back to using Visual studio 2013, where CRT dll's are only two: msvcp120.dll, msvcr120.dll.

Of course you will probably recommend to install Visual studio 2015 run-times, but one of our requirement is to support standalone executable - which works without any installation - so additional installation is out of question for now.

Can you recommend me anything else than to wait Visual studio 2017 to arrive ?

解决方案

(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.

这篇关于Visual studio 2015运行时依赖或如何摆脱Universal CRT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆