C++ – A C++ Application Compiled With VS2008 Doesn’t Run In Other Computer

cvisual c++visual studiovisual-studio-2008winapi

I have created a wn32 project with Visual Studio 2008 and Visual C++ language, it uses the ws2_32.lib library and then I compiled in Release mode.

It runs very good in the same computer, but when I copy the exe file to other computer (that doesn't have installed Visual Studio), it doesn't run.

The message I see is:

This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.

But, if I compile my application using DEV C++, it generates a bigger executable (738KB) compared with the Visual Studio 2008 executable (9.5 KB). However, the DEV C++ executable runs in the other computer.

I have add the library ws2_32.lib to the linker properties of my project, in the Additional Dependencies field.

How can I fix it to work with Visual Studio 2008?

My code is the following: http://www.stan.com.mx/yupi/udpserver.cpp

Best Answer

I agree with JaredPar. The application you build with VS2008 is using dynamic linking, whereas the DEV C++ is linking statically, hence the larger size and why one works and not the other.

However, if its a plain win32 application project you've got (and you don't want/need to distribute it with a setup), you may be able to get it to run on another machine without redistributing the CRT by getting VS2008 to link statically for you (if its just the standard lib you're missing). I don't have a copy of VS2008 to hand, so I'll describe how to do it in VS2005 and hopefully it'll translate across.

  1. Bring up configuration properties for the project (right click the project name, then select "properties" from the menu)
  2. Expand "Configuration Properties", then "C/C++", then click "Code Generation"
  3. Under the "Runtime Library" item, for your particular configuration select the non-DLL version of the library i.e. for debug builds you want "Multi-threaded Debug (/MTd) and for release builds you want "Multi-threaded (/MT)"

Try and see if that works. You'll obviously get a much bigger final binary now the library is statically linked.