在 VS 中编译 C++,而无需在运行时使用 MSVCP120D.dll

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20890458/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 23:22:46  来源:igfitidea点击:

Compile C++ in VS without requiring MSVCP120D.dll at runtime

c++dllvisual-studio-2013

提问by dlkulp

I'm trying to make a binary that can be run on any windows machine without the visual c++ stuff installed (I'm assuming that's what MSVCP120D.dll is however my searching was not very fruitful as to what this actually is). I made a game for an assignment and wanted to have other people (non-devs without VS stuff installed), help me test it but they kept getting errors saying that the above dll is missing. I'm not using any Visual C++ stuff and have the /Za flag set to ensure that it's just ANSI C++. Does Visual Studio support compiling ANSI C++ and if so how do I go about making it not use Visual C++ stuff, if it doesn't support this what compiler should I use?

我正在尝试制作一个可以在没有安装 Visual C++ 东西的情况下在任何 Windows 机器上运行的二进制文件(我假设这就是 MSVCP120D.dll 是什么,但是我的搜索并不是很有效,这实际上是什么)。我为一项任务制作了一个游戏,并希望让其他人(没有安装 VS 的非开发人员)帮助我测试它,但他们不断收到错误消息,说缺少上述 dll。我没有使用任何 Visual C++ 的东西,并且设置了 /Za 标志以确保它只是 ANSI C++。Visual Studio 是否支持编译 ANSI C++,如果支持,我该如何让它不使用 Visual C++ 的东西,如果它不支持这个,我应该使用什么编译器?

回答by John Dibling

As you can see here, the MSVCP DLL is the platform's implementation of the C++ Standard Library. In short what that means is you cannotdistribute your application without needing the "stuff" that these libraries provide. All compilers regardless of platform would need some kind of implementation of the Standard Library. Typically this is distributed in the form of libraries.

正如您在此处看到的,MSVCP DLL 是 C++ 标准库的平台实现。简而言之,这意味着您不能在不需要这些库提供的“东西”的情况下分发您的应用程序。无论平台如何,所有编译器都需要某种标准库的实现。通常,这以库的形式分发。

However you can distribute your application so that the "stuff" is built in to your program directly, rather than being shipped in a separate DLL. In order to do this, you must statically link your application to the Standard Library.

但是,您可以分发您的应用程序,以便将“东西”直接内置到您的程序中,而不是在单独的 DLL 中提供。为此,您必须将应用程序静态链接到标准库。

There are a few ways to accomplish this. One way is in Project Settings. In "Project" > "Configuration Properties" > "C/C++ Code Generation" > "Runtime Library", choose "Multithreaded (/MT)" as opposed to "Mutithreaded (Static)".

有几种方法可以实现这一点。一种方法是在项目设置中。在“项目”>“配置属性”>“C/C++ 代码生成”>“运行时库”中,选择“多线程(/MT)”而不是“多线程(静态)”。



By the way, the "D" in "MSVCP120D.dll" you mentioned above means "Debug." This means that you are trying to distribute a debugbuild of your program. You should (almost) never do this. Distribute release builds instead.

顺便说一下,你上面提到的“MSVCP120D.dll”中的“D”是指“调试”。这意味着您正在尝试分发程序的调试版本。你应该(几乎)永远不要这样做。而是分发发布版本。

回答by paulm

You have three options (in the order I'd recommend):

您有三个选项(按照我推荐的顺序):

  1. Don't statically link, instead get people that want to run your game install the visual studio re-distributable package. 32-bit VC 2010 version here: http://www.microsoft.com/en-us/download/details.aspx?id=5555

  2. Statically link the CRT (the dll you don't want to require at runtime) see here for details: How do I make a fully statically linked .exe with Visual Studio Express 2005?

  3. Build an app that doesn't even use the CRT at all. Here you will have to implement your own operator new that calls HeapAlloc(), and operator delete that calls HeapFree(), its an interesting challenge ;). To do this you tell the linker to ignore all default libs.

  1. 不要静态链接,而是让想要运行您的游戏的人安装 Visual Studio 可再分发包。32 位 VC 2010 版本在这里:http: //www.microsoft.com/en-us/download/details.aspx?id=5555

  2. 静态链接 CRT(您不希望在运行时需要的 dll)请参见此处了解详细信息:如何使用 Visual Studio Express 2005 制作完全静态链接的 .exe?

  3. 构建一个根本不使用 CRT 的应用程序。在这里,您必须实现自己的调用 HeapAlloc() 的运算符 new 和调用 HeapFree() 的运算符 delete,这是一个有趣的挑战;)。为此,您告诉链接器忽略所有默认库。

回答by Len Holgate

Build with the static runtime libraries rather than the DLL versions.

使用静态运行时库而不是 DLL 版本进行构建。

Go to Properties, C/C++, Code Generation, Runtime Library and select /MTd or /MT rather than the /MDd and /MD options.

转到属性、C/C++、代码生成、运行时库并选择 /MTd 或 /MT 而不是 /MDd 和 /MD 选项。

回答by David Heffernan

Configure your project to link against the runtime statically rather than dynamically.

将您的项目配置为静态而不是动态地链接到运行时。

回答by jcoder

First of all the D on the end of the name indicated a debug build. If you make a release build then it will need it without the D. This is important because microsoft do not allow the debug libraries to be distributed without visual studio.

首先,名称末尾的 D 表示调试版本。如果您进行发布版本,那么它将需要没有 D 的版本。这很重要,因为 microsoft 不允许在没有 Visual Studio 的情况下分发调试库。

The machine you are trying to run the program on may already have the release runtime installed as lots of programs use it. If not then install http://www.microsoft.com/en-us/download/details.aspx?id=30679on the machine ( I think that's the right one but can't check at the moment)

您尝试在其上运行程序的机器可能已经安装了发布运行时,因为许多程序都在使用它。如果没有,则在机器上安装http://www.microsoft.com/en-us/download/details.aspx?id=30679(我认为这是正确的,但目前无法检查)

回答by txtechhelp

You'll want static linking, that 'builds in' the external library calls into your binary. It does have the added affect of larger binary file, but in your case that doesn't sound like that big of a deal.

您将需要静态链接,即“内置”外部库调用到您的二进制文件中。它确实具有更大的二进制文件的附加影响,但在您的情况下,这听起来没什么大不了的。

On a side note, MSVCP120D.dll is the Microsoft Visual C++ 12 debug DLL(dynamic link library) that contains all of debug C++ libaries (i.e. iostream, string, etc). That library is what you would be 'baking in' to your final binary.

在一个侧面说明,MSVCP120D.dll是Microsoft Visual C++ 12 debug DLL一个包含所有调试C ++ libaries(即(动态链接库)iostreamstring等等)。该库是您将“烘焙”到最终二进制文件中的内容。

Hope that helps.

希望有帮助。

回答by Christopher Settles

I encountered this error when I tried to execute my exe on a different machine that had a newer version of Visual Studio on it. You need to change the project properties and re compile in order for this to go away.

当我尝试在装有较新版本 Visual Studio 的另一台机器上执行我的 exe 时遇到此错误。您需要更改项目属性并重新编译以使其消失。

To do this:

去做这个:

  1. Open up solution that you are trying to run
  2. Right click on the Project file - > Properties
  3. In Configuration Properties and General, Ensure Platform Toolset is configured to be the correct compiler on your machine. If it is not correct, it should give a message next to it saying that it's not installed.
  4. Build and run the code again and you should no longer get the issue.
  1. 打开您尝试运行的解决方案
  2. 右键单击项目文件-> 属性
  3. 在配置属性和常规中,确保平台工具集配置为您机器上的正确编译器。如果它不正确,它应该在它旁边给出一条消息,说它没有安装。
  4. 再次构建并运行代码,您应该不会再遇到此问题。