我使用2015在C++ Windows容器中生成代码
msbuild /p:Configuration=Debug本质上使用/MDd选项运行cl.exe,并生成不可用的可执行文件--参见下面。
/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如您所见,我通过巧克力包安装了2015。
我读过文档:https://learn.microsoft.com/en-us/cpp/build/reference/md-mt-ld-use-run-time-library
因此,/MDd定义了_DEBUG,并将MSVCRTD.lib放在.obj文件中,而不是MSVCRT.lib中。
在我的笔记本电脑上,我安装了完整的Visual,而且它构建得很好。
我比较了我在C:\Program Files (x86)\Microsoft Visual Studio 14.0下安装的C:\Program Files (x86)\Microsoft Visual Studio 14.0,这两个系统上的文件都是相同的。
困惑..。
发布于 2017-07-20 00:38:33
解出
容器没有GUI,编译后的.exe试图使用以下消息显示GUI对话框:
“由于计算机中缺少ucrtbased.dll,程序无法启动。请尝试重新安装该程序以解决此问题。”
(在类似的环境中运行构建.exe时发现了这一点,但使用了GUI)
有趣的是,2015年C++构建工具将这些dll-s安装在:
然而,当.exe运行时,它无法找到它们。
在完整的VS安装中,我发现这些文件也被复制在
重新安装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\https://stackoverflow.com/questions/45197682
复制相似问题