problems with running exe file built with Visual S

2019-01-17 15:37发布

问题:

I created a client server application in C++ using Visual Studio.

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:

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?

回答1:

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).

On MSDN, there is a nice article called Redistributing Visual C++ Files (for Visual Studio 2008), that states that there are Potential run-time errors in case that required Visual C++ library is not installed:

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.
Basically you have two options:
  • 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 Generation you will find Runtime Library option. 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.

But your application might depend on other DLLs as well. In case you want to find out what are the dependencies of your program, there is a great utility called Dependency Walker, that will help you in this and many other situations :)



回答2:

Background:

  • C++ applications Need run-time assemblies (DLLs) to run in any windows computer.
  • Normally these run-time assemblies located at C:\Windows\Winsxs directory.
  • All the windows operating systems by default comes with several run time assemblies.
  • But If your application developed in newer version of Run-time assembly environment, The target computer also need the same version of run time exist there.
  • When you installing visual studio most newer versions of run-time assemblies comes to your computer.

Soloution: Finally by anyway target computer should have the exact run time assemblies. There are few ways to do this (for more details search in google each).

  1. Statically link run-time assemblies with your application (Troublesome for large application).
  2. Install C++ redistribution environment in target computer(most easy way).
  3. Creating a setup project to deploy run-time in target computer when installing application. (Not bad)
  4. Deploying run-time assemblies as private assemblies (professional) see here for more details

Conditions:

  • You must not use .NET framework in your application.
  • You must not use common language run-time support for your application


回答3:

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:

1) Change the compile mode from Multithreaded DLL to 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.

2) Install the windows redistributable on the target machine. This probably isn't ok b/c you state that you don't want to install anything on the target machine.

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.



回答4:

I deployed my program in release instead of debug and the exe now works on the other computer



回答5:

Look like youre missing some DLL files. Be sure to copy appropriate dll's along with exe.