0

我建立内部的Windows容器 C++代码使用Microsoft Visual C++生成工具2015年微软的Visual C++与/ MDD产生的Windows容器内破可执行

msbuild /p:Configuration=Debug基本运行cl.exe/MDd选项,并产生不可执行 - 见下面。

/p:Configuration=Release使用/MD并使得完美的可执行文件。

示例代码hello-world.cxx

#include <iostream> 
int main() 
{ 
    std::cout << "Hello World!"; 
} 

/MDd编译:

> cl.exe /EHsc /MDd hello-world.cxx 
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24210 for x86 
Copyright (C) Microsoft Corporation. All rights reserved. 

hello-world.cxx 
Microsoft (R) Incremental Linker Version 14.00.24210.0 
Copyright (C) Microsoft Corporation. All rights reserved. 

/out:hello-world.exe 
hello-world.obj 

> echo %ERRORLEVEL% 
0 
> hello-world.exe 
    ...nothing is printed here... 
> echo %ERRORLEVEL% 
-1073741515 

/MD编译:

> cl.exe /EHsc /MD hello-world.cxx 
... 
> hello-world.exe 
Hello World! 
> echo %ERRORLEVEL% 
0 

这里是我Dockerfile的相关部分:

FROM microsoft/windowsservercore 
... 
# Install chocolatey ... 
... 
# Install Visual C++ Build Tools, as per: https://chocolatey.org/packages/vcbuildtools 
RUN choco install -y vcbuildtools -ia "/InstallSelectableItems VisualCppBuildTools_ATLMFC_SDK" 
# Add msbuild to PATH 
RUN setx /M PATH "%PATH%;C:\Program Files (x86)\MSBuild\14.0\bin" 
# Test msbuild can be accessed without path 
RUN msbuild -version 

正如你可以看到我安装Visual C++编译通过巧克力包装工具2015年。

我读过的文档:https://docs.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library

所以/MDd定义_DEBUG也放置MSVCRTD.lib成obj文件,没有MSVCRT.lib

在我的笔记本电脑,我已经安装了完整的Visual Studio和它建立的罚款。

我比较了MSVCRTD.lib,我已经安装在C:\Program Files (x86)\Microsoft Visual Studio 14.0下,并且在两个系统上的文件都是一样的。

困惑......

回答

1

解决

容器没有GUI,并编译的.exe试图展示GUI对话框,显示消息:

“程序无法启动,因为您的 计算机中缺少ucrtbased.dll,请尝试重新安装程序来解决此问题。“

(在建立时运行时发现。在类似的环境,但与GUI的exe)

有趣的是C++生成工具2015年安装在这些DLL-S:

  • C:\ Program Files文件(x86)的\的Windows套件\ 10 \ BIN \ 64 \ ucrt \
  • C:\ Program Files文件(x86)的\的Windows套件\ 10 \ BIN \ 86 \ ucrt \

然而.exe文件运行时,它无法找到他们。

在充分VS安装,我发现这些文件还下

  • Ç复制:\ WINDOWS \ SYSTEM32 \
  • C:\ WINDOWS \ Syswow64资料\

的C重装++构建工具帮助,但它很慢,感觉很奇怪。 所以我最终只是手动复制这些文件。

加入Dockerfile:

RUN copy "C:\Program Files (x86)\Windows Kits\10\bin\x64\ucrt\ucrtbased.dll" C:\Windows\System32\ 
RUN copy "C:\Program Files (x86)\Windows Kits\10\bin\x86\ucrt\ucrtbased.dll" C:\Windows\SysWOW64\ 
相关问题