简体   繁体   English

非托管 C++ 程序集的加载顺序(特别是 VS C++ 2015 可再发行组件和通用 CRT)

[英]The loading order for unmanaged C++ assemblies ( specifically VS C++ 2015 redistributables and Universal CRT)

This is similar to the question here , but it pertains to the unmanaged C++ assemblies, instead of managed.Net ones.这与此处的问题类似,但它与非托管 C++ 程序集有关,而不是托管.Net 程序集。

Assuming that my application directory has its own Visual Studio Redistributable 2015 runtime DLLs ( I redistribute the runtime at app directory, just in case the client machine cannot install the VC++ redistributables from Windows update), and the client machine also has Visual Studio Redistributable 2015 package installed.假设我的应用程序目录有自己的 Visual Studio Redistributable 2015 运行时 DLL(我在 app 目录中重新分发运行时,以防万一客户端机器无法安装 Windows 更新中的 VC++ 可再发行组件),并且客户端机器也有 Visual Studio Redistributable 2015 ZEFE90A8E604A7C640E887安装。 Which one will get loaded, the vcruntime140.dll located at the application directory, or the vcruntime140.dll installed?哪个将被加载,位于应用程序目录的vcruntime140.dllvcruntime140.dll安装?

Similarly, my application directory has its own set of Universal C Runtime ( Again, I do this out of the reason that some client machines cannot install Universal CRT due to various reasons), and in the case the client machines also have Universal CRT installed, which one will get loaded, the installed Universal CRT DLLs, or the ones at my application directory?同样,我的应用目录有自己的一套Universal C Runtime (同样,我这样做是出于某些客户端机器由于各种原因无法安装Universal CRT的原因),并且在客户端机器也安装了Universal CRT的情况下,哪一个会被加载,安装的通用 CRT DLL,还是我的应用程序目录中的那些?

For Windows 10 and Universal CRT, I know that the Universal CRT in the system directory is always used , even if an application includes an application-local copy of the Universal CRT.对于 Windows 10 和 Universal CRT,我知道始终使用系统目录中的 Universal CRT ,即使应用程序包含 Universal CRT 的应用程序本地副本。 It's true even when the local copy is newer, because the Universal CRT is a core operating system component on Windows 10.即使本地副本较新也是如此,因为通用 CRT 是 Windows 10 上的核心操作系统组件。

But I am not sure about other Windows 10, and above Visual Studio C++ redistributable package.但我不确定其他 Windows 10 及以上 Visual Studio C++ 可再发行 package。

Thus I am looking for answers on all supported Windows versions, including Windows 7, Windows 8.1 and Windows 10 .因此,我正在寻找所有受支持的 Windows 版本的答案,包括Windows 7、Windows 8.1ZAEA23489CE3AA9B6406EBB208E3AA9B6406EBB2043

Note: I am calling the unmanaged C++ assemblies from.Net, if that matters.注意:如果重要的话,我从.Net 调用非托管 C++ 程序集。

The load order for your CRT dll's are in the following order: CRT dll 的加载顺序如下:

  • Directory from where app was started启动应用程序的目录
  • Current directory当前目录
  • System directory系统目录
  • Windows directory Windows 目录
  • Path environment variables.路径环境变量。

You can place your runtime dll's in the app's current dir, and they should load.您可以将运行时 dll 放在应用程序的当前目录中,它们应该会加载。 If you are compiling on Windows 10 and don't want UCRT refrences, compile with /NODEFAULTLIB如果您在 Windows 10 上编译并且不想要UCRT ,请使用/NODEFAULTLIB编译

Or, you can statically link to the CRT libraries using the compile option /MT或者,您可以使用编译选项/MT静态链接到CRT

You can just force link to the legacy CRT if you want.如果需要,您可以强制链接到旧版 CRT。 I'm not familiar enough with the internals of uCRT to answer dependency order (and on mobile so can't check) but you can look for yourself.我对 uCRT 的内部结构不够熟悉,无法回答依赖顺序(在移动设备上所以无法检查),但你可以自己寻找。 You can download depends.exe to walk the dependencies statically as well as Process Explorer to view where each CRT image was loaded from dynamically.您可以下载depends.exe以静态遍历依赖项,也可以下载Process Explorer以查看每个CRT 图像的动态加载位置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM