我建立内部的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
下,并且在两个系统上的文件都是一样的。
困惑......