views:

971

answers:

4

Hi, 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

+10  A: 

The problem is almost certainly that the other computer does not have version 9 of the C++ CRT installed.

The default setting for compiling against the CRT in VS2008 is to dynamically link vs. statically linking. If you want to deploy your program with a real setup project you'll need to include the CRT redistributable.

However if you want to do an XCOPY deployment follow the steps on the following page.

http://msdn.microsoft.com/en-us/library/ms235291.aspx

JaredPar
A: 

You may be missing an external dependency required by your program. Check the project settings to see if you are linking against MFC dynamically for example. You can also run Depends utility to check for missing dependencies.

Brian Ensink
+3  A: 

Try installing the Visual C++ redistributables. If that doesn't work, use DependencyWalker to find out what DLLs are missing.

Not Sure
+1  A: 

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.

porkchop