visual-studio Visual C++/Studio:应用程序配置不正确?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/99479/
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-09-13 16:32:34  来源:igfitidea点击:

Visual C++/Studio: Application configuration incorrect?

c++cvisual-studiovisual-c++

提问by Thomas

My C(++) program, written and compiled using Visual C(++)/Visual Studio, runs fine on my own machine, but refuses to run on another machine. The error message I get is "This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem."

我的 C(++) 程序,使用 Visual C(++)/Visual Studio 编写和编译,在我自己的机器上运行良好,但拒绝在另一台机器上运行。我收到的错误消息是“此应用程序无法启动,因为应用程序配置不正确。重新安装应用程序可能会解决此问题。”

回答by Charlie

The problem here is a missing DLL dependency, such as the CRT (C Runtime Library). A good tool for diagnosing this sort of problem is Dependency Walker (depends.exe), which you can find here:

这里的问题是缺少 DLL 依赖项,例如 CRT(C 运行时库)。诊断此类问题的一个好工具是 Dependency Walker (depends.exe),您可以在此处找到它:

http://www.dependencywalker.com/

http://www.dependencywalker.com/

You would run this program on the computer that generates the error message you posted, and use it to open the exe that's generating this error. Dependency Walker will quickly and graphically indicate any DLLs that are required but not available on the machine.

您将在生成您发布的错误消息的计算机上运行此程序,并使用它打开生成此错误的 exe。Dependency Walker 将快速并以图形方式指示机器上需要但不可用的任何 DLL。

回答by Thomas

If you write a C++ program, it links dynamically to the C Runtime Library, or CRT for short. This library contains your printf, your malloc, your strtok, etcetera. The library is contained in the file called MSVCR80.DLL. This file is not by default installed on a Windows system, hence the application cannot run.

如果您编写 C++ 程序,它会动态链接到 C 运行时库,简称 CRT。这个库包含你的 printf、你的 malloc、你的 strtok 等等。该库包含在名为 MSVCR80.DLL 的文件中。默认情况下,此文件未安装在 Windows 系统上,因此该应用程序无法运行。

The solution? Either install the DLL on the target machine through VCREDIST.EXE (the Visual C++ Redistributable Package), or link to the CRT statically (plug the actual code for the used functions straight into your EXE).

解决方案?通过 VCREDIST.EXE(Visual C++ Redistributable Package)在目标机器上安装 DLL,或者静态链接到 CRT(将所用函数的实际代码直接插入到您的 EXE 中)。

Distributing and installing VCREDIST along with a simple application is a pain in the arse, so I went for the second option: static linking. It's really easy: go to your project's properties, unfold C/C++, click Code Generation, and set the Runtime Library to one of the non-DLL options. That's all there is to it.

分发和安装 VCREDIST 以及一个简单的应用程序是一件很麻烦的事情,所以我选择了第二个选项:静态链接。这真的很简单:转到项目的属性,展开 C/C++,单击代码生成,然后将运行时库设置为非 DLL 选项之一。这里的所有都是它的。

回答by sorin

First thing you must use

你必须使用的第一件事

#define _BIND_TO_CURRENT_VCLIBS_VERSION 1

or add _BIND_TO_CURRENT_VCLIBS_VERSION=1to the preprocessor directives.

或添加_BIND_TO_CURRENT_VCLIBS_VERSION=1到预处理器指令。

The problem is related to binding and the manifest types, you can find more http://www.nuonsoft.com/blog/2008/10/29/binding-to-the-most-recent-visual-studio-libraries/

问题与绑定和清单类型有关,您可以找到更多http://www.nuonsoft.com/blog/2008/10/29/binding-to-the-most-recent-visual-studio-libraries/

By doing this your application will run with a larger range of runtime libraries versions.

通过这样做,您的应用程序将使用更大范围的运行时库版本运行。

回答by mad_dog

POSSIBLE SOLUTION........

可能的解决方案......

EDIT: (removed most of my post) Long story short, I was having similar problems, getting the "Application Configuration Incorrect" messages, etc etc. Depends.exe was only finding ieshims.dll and wer.dll as possible issues, but this is not the problem. I ended up using the Multithreaded (/mt) compile option. What HAS worked though, as a workable solution, is making an installer with InstallShield. I've selected several merge modules in installshield builder and this seems to have fixed my problem. The modules selected were: VC++ 9.0 CRT, VC++ 9.0 DEBUG CRT, and the CRT WinSXS MSM merge module. I'm pretty sure its the WinSXS merge module that has fixed it.

编辑:(删除了我的大部分帖子)长话短说,我遇到了类似的问题,收到“应用程序配置不正确”消息等。 Depends.exe 只发现 ieshims.dll 和 wer.dll 作为可能的问题,但这不是问题。我最终使用了多线程 (/mt) 编译选项。然而,作为一个可行的解决方案,有效的方法是使用 InstallShield 制作安装程序。我在 installshield builder 中选择了几个合并模块,这似乎解决了我的问题。所选模块为:VC++ 9.0 CRT、VC++ 9.0 DEBUG CRT 和 CRT WinSXS MSM 合并模块。我很确定它的 WinSXS 合并模块已经修复了它。

DEBUG CRT: I noticed somewhere that (no matter how hard I tried, and obviously failed thus far), my Release version still depended on the DEBUG CRT. If this is still the case, the InstallShield merge module has now placed the DEBUG CRT folder in my WinSXS folder :) Being somewhat of a novice with VC++ I assume that this would normally be used to distribute debug versions of your programs to other people. To test if this is what fixed my problem I removed the DEBUG CRT folder from the WinSXS folder and the application still worked. (Unless something is still running in the background etc etc - I'm not that into it)

DEBUG CRT:我在某处注意到(无论我多么努力尝试,到目前为止显然都失败了),我的 Release 版本仍然依赖于 DEBUG CRT。如果情况仍然如此,InstallShield 合并模块现在已将 DEBUG CRT 文件夹放在我的 WinSXS 文件夹中 :) 作为 VC++ 的新手,我认为这通常用于将程序的调试版本分发给其他人。为了测试这是否解决了我的问题,我从 WinSXS 文件夹中删除了 DEBUG CRT 文件夹,应用程序仍然可以工作。(除非有什么东西仍在后台运行等等 - 我不是那么喜欢它)

Anyway, this has got things working for me on an XP SP3 fully updated machine, and also on a VMWare XP SP3 machine with the bare bones (.net 3.5 and VC++ 2008 RTM basically) - and also on a mate's XP machine where it previously wasn't working.

无论如何,这让我在 XP SP3 完全更新的机器上工作,以及在具有裸机(.net 3.5 和 VC++ 2008 RTM 基本上)的 VMWare XP SP3 机器上工作 - 以及在以前的伴侣的 XP 机器上没有工作。

So give these things a try, you might have some luck.

所以试试这些东西,你可能会有一些运气。

回答by Drealmer

Chances are high that you miss the runtime libraries of Visual Studio (CRT amongst others), you can either get rid of those dependencies (link statically) or install the VC redist packages on the target computer.

您很可能会错过 Visual Studio 的运行时库(CRT 等),您可以摆脱这些依赖项(静态链接)或在目标计算机上安装 VC redist 包。

Depending on the Visual C++ version you use, you have to install different packages :

根据您使用的 Visual C++ 版本,您必须安装不同的软件包:

Visual C++ 2005

可视化 C++ 2005

Visual C++ 2005 SP1

Visual C++ 2005 SP1

Visual C++ 2008

可视化 C++ 2008

Warning: those packages only contain release versions of the libraries, if you want to be able to distribute debug builds of your application you'll have to take care of the required DLL yourself.

警告:这些包仅包含库的发布版本,如果您希望能够分发应用程序的调试版本,则必须自己处理所需的 DLL。

回答by ravenspoint

It is much the simplest to link to the runtime statically.

静态链接到运行时最简单。

c++ -> Code Generation -> Runtime Library and select "multi-threaded /MT"

c++ -> 代码生成 -> 运行时库并选择“多线程/MT”

However, this does make your executable a couple hundred KByte larger. This might be a problem if you are installing a large number of small programs, since each will be burdened by its very own copy of the runtime. The answer is to create an installer.

但是,这确实会使您的可执行文件大几百 KByte。如果您要安装大量小程序,这可能是一个问题,因为每个小程序都将受到其自己的运行时副本的负担。答案是创建一个安装程序。

New project -> "setup and deployment" -> "setup project"

新建项目->“设置和部署”->“设置项目”

Load the output from your application projects ( defined using the DLL version of the runtime ) into the installer project and build it. The dependency on the runtime DLL will be noticed, included in the installer package, and neatly and unobtrusively installed in the correct place on the target machine.

将应用程序项目的输出(使用运行时的 DLL 版本定义)加载到安装程序项目中并构建它。对运行时 DLL 的依赖将被注意到,包含在安装程序包中,并整齐且不显眼地安装在目标机器上的正确位置。

回答by Scott

The correct VC Redist package for you is part of your Visual Studio installation. For VC 8, you can find it here:

正确的 VC Redist 包是 Visual Studio 安装的一部分。对于 VC 8,您可以在这里找到它:

\Program Files\Microsoft Visual Studio 8\SDK\v2.0\BootStrapper\Packages\vcredist_x86

回答by Tim

Note also - that if you change to static runtime, you will have to do the same for MFC if your app uses MFC. Those settings are in properties->Configuration/General

另请注意 - 如果您更改为静态运行时,并且您的应用程序使用 MFC,则您必须对 MFC 执行相同操作。这些设置在属性->配置/常规中

回答by Jeff

I ran into this problem and was able to fix it very simply.

我遇到了这个问题,并且能够非常简单地解决它。

Visual studio gives you the option (on by default) to build a manifest for each build.

Visual Studio 为您提供了为每个构建构建清单的选项(默认开启)。

The manifest was put in the release folder, but it was a different release folder than the exe.

清单放在发布文件夹中,但它与 exe 是不同的发布文件夹。

Even when using the setup utilities it was not packaged.

即使在使用设置实用程序时,它也没有打包。

You should look for a file names something like myprogram.exe.indermediate.manifest

您应该查找类似于 myprogram.exe.indermediate.manifest 的文件名

If this is in the same folder as the exe (and you have all the dlls) it should run

如果它与 exe 位于同一文件夹中(并且您拥有所有 dll),则它应该运行

回答by BeachRunnerFred

Often times this error is the result of attempting to run the debug version of an application that uses .NET. Since the .NET redistributable package doesn't include the debug versions of the dlls that are installed with Visual Studio, your application will often get this error when running it on any other machine that doesn't have Visual Studio installed. If you haven't already, try building a release version of your application and see if that works.

通常,此错误是尝试运行使用 .NET 的应用程序的调试版本的结果。由于 .NET 可再发行组件包不包含随 Visual Studio 安装的 dll 的调试版本,因此您的应用程序在未安装 Visual Studio 的任何其他计算机上运行时通常会出现此错误。如果您还没有,请尝试构建应用程序的发布版本,看看是否有效。