C++ 在另一台计算机上运行使用 Visual Studio 构建的 EXE 文件的问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15297270/
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
Problems with running EXE file built with Visual Studio on another computer
提问by Karen123456
I created a client server application in C++ using Visual Studio.
我使用 Visual Studio 在 C++ 中创建了一个客户端服务器应用程序。
Now I want to run the client EXE file on another computer (which doesn't have Visual Studio installed), but when I try run the EXE file, it gives the following error message:
现在我想在另一台计算机(没有安装 Visual Studio)上运行客户端 EXE 文件,但是当我尝试运行 EXE 文件时,它给出了以下错误消息:
This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.
此应用程序无法启动,因为应用程序配置不正确。重新安装应用程序可能会解决此问题。
How can I run the EXE file without installing anything on the computer?
如何在不在计算机上安装任何东西的情况下运行 EXE 文件?
采纳答案by Karen123456
I deployed my program in release instead of debug, and the EXE file now works on the other computer.
我在发布而不是调试中部署了我的程序,并且 EXE 文件现在可以在另一台计算机上运行。
回答by LihO
Applications built with Visual Studio depend on Visual C++ Redistibutable (VCRedist). When the program is being linked dynamically, then your binaries will need
MSVCR**.dll
(Microsoft C Runtime Library).
使用 Visual Studio 构建的应用程序依赖于 Visual C++ Redistibutable (VCRedist)。当程序被动态链接时,您的二进制文件将需要
MSVCR**.dll
(Microsoft C 运行时库)。
On MSDN, there is a nice article called Redistributing Visual C++ Files (for Visual Studio 2008), that states that there are Potential run-time errorsin case that required Visual C++ library is not installed:
在 MSDN 上,有一篇名为Redistributing Visual C++ Files (for Visual Studio 2008)的好文章,指出在未安装所需的 Visual C++ 库的情况下存在潜在的运行时错误:
you may get one of the following error messages depending on the version of Windows on which you try to run your application:
- The application failed to initialize properly (0xc0000135).
- This application has failed to start because the application configuration is incorrect. Reinstalling application may fix this problem.
- The system cannot execute the specified program.
基本上你有两个选择:根据您尝试运行应用程序的 Windows 版本,您可能会收到以下错误消息之一:
- 应用程序未能正确初始化 (0xc0000135)。
- 此应用程序无法启动,因为应用程序配置不正确。重新安装应用程序可能会解决此问题。
- 系统无法执行指定的程序。
- The simplest possible solution is to change the dynamic linking of runtime libraries to static linking. Go to project properties and under C/C++ → Code Generationyou will find Runtime Libraryoption. You need to change it from Multi-threaded DLL (/MD)to Multi-threaded (/MT).
- Another possible solution is to make sure that the right version of Microsoft VC++ Redistributable Package is installed on the target machine.
- 最简单的可能解决方案是将运行时库的动态链接更改为静态链接。转到项目属性,然后在C/C++ → 代码生成下找到运行时库选项。您需要将其从Multi-threaded DLL (/MD)更改为Multi-threaded (/MT)。
- 另一种可能的解决方案是确保目标计算机上安装了正确版本的 Microsoft VC++ Redistributable Package。
But your application might depend on other DLL files as well. In case you want to find out what are the dependencies of your program, there is a great utility called Dependency Walkerthat will help you in this and many other situations :)
但是您的应用程序也可能依赖于其他 DLL 文件。如果您想了解您的程序的依赖项是什么,有一个名为Dependency Walker 的实用工具可以在这种情况和许多其他情况下为您提供帮助:)
回答by Nayana Adassuriya
Background:
背景:
- C++ applications needrun-time assemblies (DLL files) to run in any Windows computer.
- Normally these run-time assemblies are located at C:\Windows\Winsxs directory.
- All the Windows operating systems by default comes with several run time assemblies.
- But if your application is developed in a newer version of the run-time assembly environment, the target computer also needs the same version of the run time to exist there.
- When you're installing Visual Studio, most newer versions of the run-time assemblies comes to your computer.
- C++ 应用程序需要运行时程序集(DLL 文件)才能在任何 Windows 计算机上运行。
- 通常,这些运行时程序集位于 C:\Windows\Winsxs 目录中。
- 默认情况下,所有 Windows 操作系统都带有几个运行时程序集。
- 但是,如果您的应用程序是在较新版本的运行时程序集环境中开发的,那么目标计算机也需要存在相同版本的运行时。
- 安装 Visual Studio 时,大多数较新版本的运行时程序集都会出现在您的计算机上。
Solution:
解决方案:
Finally by anyway the target computer should have the exact run time assemblies. There are a few ways to do this (for more details search each in Google).
最后无论如何目标计算机应该有确切的运行时程序集。有几种方法可以做到这一点(有关更多详细信息,请在 Google 中搜索每种方法)。
- Statically link run-time assemblies with your application (troublesome for large application).
- Install the C++ redistribution environment on the target computer (the easiest way).
- Creating a setup project to deploy the run-time on the target computer when installing the application (not bad).
- For deploying run-time assemblies as private assemblies (professional), see herefor more details
- 将运行时程序集与您的应用程序静态链接(对于大型应用程序来说很麻烦)。
- 在目标计算机上安装 C++ 重新分发环境(最简单的方法)。
- 创建安装项目以在安装应用程序时在目标计算机上部署运行时(不错)。
- 要将运行时程序集部署为私有程序集(专业),请参阅此处了解更多详细信息
Conditions:
状况:
- You must not use .NET framework in your application.
- You must not use the common language run-time support for your application
- 您不得在您的应用程序中使用 .NET 框架。
- 您不得为您的应用程序使用公共语言运行时支持
回答by john.pavan
I haven't seen that specific error before. Usually it's an error around a missing DLL (Windows redistributable). Assuming there isn't actually a problem with the configuration, you have two choices:
我以前没有见过那个特定的错误。通常是因为缺少 DLL(Windows 可再发行组件)而导致的错误。假设配置实际上没有问题,您有两种选择:
Change the compile mode from Multithreaded DLLto Multithreaded. This can be done from the C++ section of project properties under code generation. In multithreaded mode your binary will be statically linked against the Windows redistributable. This is probably what you want.
Install the Windows redistributable on the target machine. This probably isn't OK, because you state that you don't want to install anything on the target machine.
将编译模式从Multithreaded DLL更改为Multithreaded。这可以从代码生成下项目属性的 C++ 部分完成。在多线程模式下,您的二进制文件将与 Windows 可再发行组件静态链接。这可能就是你想要的。
在目标计算机上安装 Windows 可再发行组件。这可能不好,因为您声明不想在目标机器上安装任何东西。
A warning about option 1: Different versions of Windows have different versions of the redistributable. It's possible to encounter a highly specialized environment in which a statically linked program will not behave as expected.
关于选项 1 的警告:不同版本的 Windows 具有不同版本的可再发行组件。可能会遇到高度专业化的环境,在该环境中静态链接的程序不会按预期运行。
回答by mag_zbc
It look like you're missing some DLL files. Be sure to copy appropriate DLL files along with EXE file.
看起来您缺少一些 DLL 文件。请务必将适当的 DLL 文件与 EXE 文件一起复制。