Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running C++ binaries without the runtime redistributable (Server2k3, XPSP3)

Having written a CGI application in Visual Studio 2008 and debigged it locally, I uploaded it to a Windows Server 2003 OS where it promptly failed to run.

I am guessing I need to install the wretched Runtime distributable, but after reading this:

http://kobyk.wordpress.com/2007/07/20/dynamically-linking-with-msvcrtdll-using-visual-c-2005/

I am wondering if it makes more sense to ignore this side by side stuff and just re-write the app.

I am guessing Windows Server 2003 does not have MSCRVT version I need? Does Windows Server 2003 have it?

When it comes to deploying thick clients, I would like to distribute the required dlls with my app. What are they assuming I just INCLUDE iostream, sstream, string?

Does it change significantly if I add windows.h?

Added:

Using the /MT switch recommended below

C / C++ -> Code Generation -> Runtime Library -> Multi-threaded(/MT)

(You will probably need to do a clean:

Build -> Clean

in order to avoid the error message

"Failed to save the updated manifest to the file")

bloated my app from 38k to 573k. Thats what I call Significant (imagine if that were your salary). Since many instances of this app will be loaded and unloaded constantly (requiring precious memory and processor resources) I would like to find a better (smaller) solution.

I understand this is not important for many situations today and not the focus of many developers, hence the trend to .NOT and 60MB runtimes, but this is what I want to do.

Added:

After removing the debugging to get the project to compile:

Project -> Propeties -> c/c++ -> Preprocessor -> Preprocessor Definitions (remove DEBUG;)

the size was reduced to 300k, and it will run.

Added: As suggested by Chris Becke below, copying: msvcm90.dll msvcp90.dll msvcr90.dll Microsoft.VC90.CRT.manifest To the directory of the application will provide all the runtime needed.

Using Visual Studio 6 has been suggested a few times, but it does not support Vista (or Windows 7 we assume) Other solutions that do not require a runtime distributable would probably me MASM or even a flavor of Basic. Unfortunately that defeats the purpose of using a high level OOP language like C++.

So long as I do need to require the C++ redistributable be installed, the trade off is an additional 260k. Thats acceptable

like image 641
Mike Trader Avatar asked Oct 17 '09 00:10

Mike Trader


2 Answers

Let me revise my answer:

You have a few options:

1) Install the VC++2008 runtime. You can download and installer for them. Merge modules for them are also available.

2) Link against the runtime statically (/MT or C/C++ -> Code Generation -> Runtime Library: Multi-threaded). This will increase the size of your executable, but it won't depend on any Dlls. If you are worried about size, only use the C standard library or only use the Windows API directly.

3) Use an older version of VC++. 2005 and earlier did not require the runtime to be installed. The Dlls could be placed in the same directory as the executable. If you use VC++6.0 the runtimes will be installed on all versions of windows, otherwise you need to install it yourself.

like image 156
Roland Rabien Avatar answered Oct 30 '22 11:10

Roland Rabien


A fuller list of options:

  • Rewrite the app so that theres no C/C++ usage at all.
  • Switch to Visual Studio 6 or a mingw based toolset like Code::Blocks - these use the already distributed msvcrt.dll as their runtime.
  • Build using the /MT switch. This builds the necessary runtime functions into your exe. Which will bloat it. But that bloat (frankly) is less overhead than loading separate dll's.
  • Distribute the VS9 runtime as a 'private sxs' install. This entails copying the contents of C:\Program Files\Microsoft Visual Studio 9.0\VC\redist\x86\Microsoft.VC90.CRT into the same folder as your application's exe. If you have applied SP1, then this folder will contain the SP1 runtime, but your application will be asking for the RTM runtime (go figure). Add _BIND_TO_CURRENT_CRT_VERSION to your projects defines, rebuild and that should sort itself out.
  • There is apparently a vc_redist.exe that can be obtained for VS9. Find that or figure out the MSI or installer mojo required to actually install the above assembly (being the contents of Microsoft.VC90.CRT) into the shared sxs store.
like image 29
Chris Becke Avatar answered Oct 30 '22 11:10

Chris Becke