Running C++ application built by VC++ Express on another computer
Another FAQ from VC++ Express users is: "I give my VC++ application to my friend, and it does not run on her computer." This happens because VC++ Dlls have to be redistributed to another computer together with this application.
There are three ways to get an application built with VC++ Express 2005 to run on another computer that does not have VC++ Express installed:
Ask user of that computer to install Visual C++ Redistributable Package (VCRedist_x86.exe) to install all Visual C++ libraries as shared side-by-side assemblies into the native assembly cache (WinSxS folder). This package can be downloaded from the Microsoft download site Microsoft Visual C++ 2005 Redistributable Package (x86). Redistributing Visual C++ libraries using this package is recommended for applications built with Visual C++ Express.
Build another installer of VC++ libraries using Redistributable Merge Modules installed by VC++ Express into Common Files\Merge Modules. I am describing this approach below in more details.
Statically link your application to VC++ libraries. I recommend against statically linking because static linking prevents your application from running against the most up todate version of VC++ libraries installed on your computer. For example, consider an application that is statically linked to a particular library, running on a client computer with a new version of this library. The application still uses code from the previous version of this library, and does not benefit from library improvements, such as security enhancements.
So if you have decided that you cannot use Microsoft Visual C++ 2005 Redistributable Package (x86) and wisely avoid statically linking to VC++ libraries, you may build a custom MSI that deployes VC++ libraries using four merge modules with CRT library installed by VC++ Express. In my case there are installed in D:\Program Files\Common Files\Merge Modules\:
D:\Program Files\Common Files\Merge Modules\
microsoft_vc80_crt_x86.msm
policy_8_0_microsoft_vc80_crt_x86.msm
microsoft_vc80_debugcrt_x86.msm
policy_8_0_microsoft_vc80_debugcrt_x86.msm
Clearly I assume that you have read the EULA and redist.txt and do understand that redistribution of debug applications is not allowed. You can simulate redist of debug binaries in your office, but if it goes outside to another computer, it must be application build in Release mode. So please read the EULA and redist.txt carefully and understand what you can and what you cannot redistribute.
I am going to show now how to one can use MSMs to install VC++ DLLs to another computer. I have VC++ Express installed on my computer and I want to make it run on another computer that does not have VC++2005 installed. Here is what I do:
1. I download WIX from sourceforge.net, here is the link https://sourceforge.net/projects/wix . More specific I am going to download from this link, https://prdownloads.sourceforge.net/wix/binaries-2.0.3220.0.zip?download but you may use another build of WiX, perhaps more recent or older then one I use.
2. I am going to unzip this package to D:\WiX\
3.Now I am going to open Visual Studio 2005 Command Prompt (Start>All Programs>Visual C++ 2005 Express Edition>Visual Studio Tools>Visual Studio 2005 Command Prompt)
4. I am typing uuidgen –n2 and click Enter. This generates two UUIDs for me that I am going to use later in Step 6.
5. Now I am going to create two XML files in D:\WiX. First VCCRT.wxi, second VCCRT.wxs.
6. First, I am creating D:\WIX\VCCRT.wxi with the following content :
<Include>
<?define PRODUCT_ID=!!!! REPLACE WITH UUID1 FROM STEP 4 !!!! ?>
<?define PACKAGE_ID=!!!! REPLACE WITH UUID2 FROM STEP 4 !!!! ?>
</Include>
Attn: I am going to use two UUIDs generated for me by uuiedgen.exe in the Step 4 to define PRODUCT_ID and PACKAGE_ID. On purpose, I am not listing UUID generated for me, so to help readers of this article avoid using same UUID as someone else.
7. Second, I am creating D:\WIX\VCCRT.wxs with following content
<?xml version='1.0'?>
<?include $(sys.SOURCEFILEDIR)\VCCRT.wxi ?>
<Wix xmlns='https://schemas.microsoft.com/wix/2003/01/wi'>
<Product Id='$(var.PRODUCT_ID)'
Name='MSI to redistribute my app'
Language='1033' Version='1.0.0.0' Manufacturer='Me'>
<Package Id='$(var.PACKAGE_ID)'
Description='MSI to redistribute my app'
Comments='MSI to redistribute my app'
Manufacturer='Me'
InstallerVersion='300'
Compressed='yes' />
<Media Id='1' Cabinet='VCCRT.cab' EmbedCab='yes' />
<Directory Id='TARGETDIR' Name='SourceDir'>
<Merge Id='CRT' Language='0' src='D:\Program Files\Common Files\Merge Modules\microsoft_vc80_crt_x86.msm' DiskId='1' />
<Merge Id='CRT Policy' Language='0' src='d:\Program Files\Common Files\Merge Modules\policy_8_0_Microsoft_VC80_CRT_x86.msm' DiskId='1' />
</Directory>
<Feature Id='CRT_WinSXS' Title='CRT WinSXS' Level='1'>
<MergeRef Id='CRT' />
<MergeRef Id='CRT Policy' />
</Feature>
<InstallExecuteSequence>
<RemoveRegistryValues/>
<RemoveFiles/>
<InstallFiles/>
<WriteRegistryValues/>
</InstallExecuteSequence>
</Product>
</Wix>
8. Now I am going back to command line, change current directory, compile and link msi
- >cd d:\WiX
- >candle.exe vccrt.wxs -out vccrt.wixobj
- >light.exe vccrt.wixobj -out vccrt.msi
9. That's it, MSI is created. It should be a file D:\WiX\vccrt.msi. If you see errors, take a look on troubleshooting section below.
10. Now I copy my application and vccrt.msi to another computer where I want this application to run which does not have VC++ Express installed. After I have copied my EXE and vccrt.msi, I will first run vccrt.msi before running my EXE.
11. Well my application works just fine. If your application does not start after MSI is installed, please see TroubleShoting section below.
Troubleshooting:
1. Error message CNDL0054 from candle.exe
candle.exe : error CNDL0054 : The document element name 'Include' is invalid. A WiX source file must use 'Wix' as the document element name.
Cause: you have tried executing >candle.exe vccrt.wxi -out vccrt.wixobj instead of >candle.exe vccrt.wxs -out vccrt.wixobj
2. Error message CNDL0009 from candle.exe
D:\WiX\vccrt.wxs(6) : error CNDL0009 : The Product/@Id attribute's value, '!!!! REPLACE WITH UUID FROM STEP 4 !!!! ', is not a legal guid value.
D:\WiX\vccrt.wxs(10) : error CNDL0009 : The Package/@Id attribute's value, '!!!! REPLACE WITH UUID FROM STEP 4 !!!!', is not a legal guid value.
Cause: Edit vccrt.wxi and replace !!!! REPLACE WITH UUID FROM STEP 4 !!!! with UUID generated in Step 4
3. Error Message CNDLXXXX from candle.exe
Cause: No idea, mistake happen when you copy/pasted XML from this post. See WiX documentation for troubleshooting.
4. Error on start of application either a message box that says "This application has failed to start because the application configuration is incorrect" or "The system cannot execute the specified program"
Cause: First, check that your application is built in Release mode. If it was Debug application, you will see OS errors that let you know that either msvcm80d.dll or msvcr80d.dll is not loaded. Second, check if you have deployed all Dependencies of this application. Use depends.exe to see dependencies of an application
5. Error message box while starting your application that says "To run this application you first must install .Net Framework of version v.2.0.xxxx".
Cause: You application contains managed code and depends on presence of .Net Framework. For C++ applications it means that it has been compiled as /clr, /clr:pure or /clr:safe. You have install .Net Framework.
6. After you have installed MSI and you run your application you still get errors described on this page in MSDN , please make sure you have done all steps exactly as they are described and repeat them. Also check out general troubleshooting section in MSDN docs for issues around deployment of Visual C++ libraries.
For any additional help with redistributing applications built with VC++ Express, please check out discussions or ask your question on
VC++ Forums, https://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=29&SiteID=1.
Comments
Anonymous
December 07, 2006
What is this utter nonsense? “Clearly I assume that you have read the EULA and redist.txt and do understand that redistribution of debug applications is not allowed. “ I need, or actually I'm required by our clients, to distribute full debug builds of all our products to our clients end user test and quality control groups. We may be talking about several hundred installations for some of our clients. So what your actually saying is that VC 8 is completely out of the question as a development tool for us and the occasional developer at the client site?Anonymous
December 07, 2006
Mikael, Neither EULA for any version of Visual Studio allows you to redistribute debug versions of VC++ libraries. It was never legal and it is not a new policy in VC8. If you would like to discuss your situation, you are welcome to contact me offline using my email nikolad at microsoft dot com. NikolaAnonymous
January 08, 2007
PingBack from http://mahtar.net/?p=32Anonymous
January 09, 2007
The comment has been removedAnonymous
January 09, 2007
The comment has been removedAnonymous
January 15, 2007
I am getting the following error after step 8c: C:WIXVCCRT.wxs(29) : fatal error LGHT0034: Cannot open merge module 'CRT' at path 'D:Program FilesCommon FilesMerge Modules I'm sure this is because the drive letter the WIX folder is in is C: not D:. How can i fix this? This seems to be the only problem. CaryAnonymous
January 16, 2007
Cary, You need to find where MSMs are installed on your computer. It may be C: or D: or any other drive. In my case, they were installed in D:Program FilesCommon FilesMerge Modules. There are four merge modules with CRT library installed by VC++ Express listed below: D:Program FilesCommon FilesMerge Modules microsoft_vc80_crt_x86.msm policy_8_0_microsoft_vc80_crt_x86.msm microsoft_vc80_debugcrt_x86.msm policy_8_0_microsoft_vc80_debugcrt_x86.msm NikolaAnonymous
January 26, 2007
So, how exactly are we supposed to distribute applications developed with VC++ Express? The very fact that we have to go through all of this contorted nonsense to create something that will run on another PC makes me believe that Microsoft never really intended us to distribute VC++ Express applications. If they had wanted us to distribute VC++ Express applications, they would have provided us with a tool to make a quick-and-easy deployment package. I really can't believe that the approach outlined here is the only way to distribute a ".exe" file. Please tell me I'm missing something here.Anonymous
January 26, 2007
Hi Michael, With VC++ Express there are two options: A) Using VCRedist.EXE that can be downloaded from MSDN site. More details in another post, http://blogs.msdn.com/nikolad/archive/2006/04/11/Download-location-for-VCRedist.aspx A) Using MSMs, as I described in this post. There are more information on deployment in MSDN, http://msdn2.microsoft.com/en-us/library/ms235299(VS.80).aspx and there are topics about this on forums, http://forums.microsoft.com/msdn/ShowForum.aspx?ForumID=29. Cheers, NikolaAnonymous
January 30, 2007
Hi Nikola, I'm trying to migrate my Win32 apps (c++ using only Win32 API), from Visual Studio 6.0 and Visual Studio 2003 to Visual Studio 2005 Pro. But unfortunately the apps get linked with Msvcr80.dll. I solved this setting in project settings-> C/C++-> Code Generation-> Runtime Library to "Multi-Threaded (/MT). But the apps size are to big. I can't deploy the Visual Studio 5 Libraries cause the apps are installed in thousands of workstations with all kind of Windows versions (95 to 2003). Is there any other option, that I can set to lose the dlls dependency? Thanks in advanceAnonymous
January 30, 2007
Hi John, I am glad to hear that you are migrating your application to VS2005. It is true that if you build application with VS2005, you at least get dependency on VC++ CRT library (msvcr80.dll). You may deploy VC++ libraries on other computers using MSMs, VCRedist.EXE or DLLs+manifest in applocal folder. These options are described in details here: < http://msdn2.microsoft.com/en-us/library/ms235299(VS.80).aspx > Thanks, NikolaAnonymous
February 05, 2007
[Rant] First of all -- I'm sorry you seem to be so happy to gloss over the removal of the ability to compile Hello World and copy to another computer and expect it to run. I realise VSE is a free product, but I don't think this is a trivial issue, and I can't believe it isn't addressed as a standard part of the distribution. Take a step back and compare it with other compiler vendors for example. If they gave the answer you have above I'd bin their product instantly (even if it was free -- and many are). Bring back Visual C++ 6! [/Rant] Sorry I know it's not really your responsibility. I just had to vent. Is it possible to link with static copies of the standard libraries instead? I would much prefer it in light of some of the problems (not least the quality of the error messages). Or would I be forced to switch to a different compiler to do that? Thanks, PS: Can you at least publish generic .msi files to save us going through the 11 point plan you proposed?Anonymous
February 05, 2007
Graham, Requirement to redistribute VC++ DLLs is not to VS2005. Even with VC6 you need to redistribute VC++ Dlls on another computer. It just happens that Windows team has also been using VC6 versions of VC++ Dlls when XP was built and they have installed that version of libraries on every computer with Windows. However this is not the same version of CRT you have on your developer machine installed by VS6. Windows continue maintaining that version of CRT, ATL and MFC which is VC6 based but contains long list of changes never released in VC6. If you run your application on these versions of DLLs, behavior of your application may be different from what you expect and what you have tested with VC6 DLLs. To conclude, you always have to redistribute VC++ DLLs with which you have tested your application, no matter this is VC6, VC7, VC71 or VC8. Yes, you can statically link and there is VCRedist package that can be downloaded from the web. Please see MSDN for more information. Thanks, NikolaAnonymous
February 07, 2007
Hi Nikola, I am developing C++ applications with VS 2005 Express and Pro. I've also had the deployment-to-another-computer problem. I understand you can solve this a) by static linking (not good for many reasons) b) by installing the VCredist_x86.exe package (ok but sometimes it's inconvenient to force users to install this first and then install one's product) c) by creating the MSI installer Now about point c). You describe a rather involved procedure to do that, which includes using some third-party tools (WiX), some manual editing, etc. My question is: isn't it possible to automate this procedure completely from the VS environment? I.e. that instead of an .exe, VS would produce the .msi file? If not, could you explain the reasons behind having this complex deployment procedure which actually involves third-party tools instead of having it in some way automated from VS? Thanks, AlexAnonymous
February 08, 2007
The comment has been removedAnonymous
February 08, 2007
Alex, >> isn't it possible to automate this procedure completely from the VS environment? Yes, VS has setup project that you can use to build a simple MSI. It may not generate and MSI that meets requirements of enterprise-level deployment. However it allows creating simple MSIs that meet most of requirements. You may find more information in docs, (http://msdn2.microsoft.com/en-us/library/ms227381(VS.80).aspx) Karsten, Please make sure you do reasonable amount of testing before using _USE_RTM_VERSION define for reasons I have mentioned in my reply on forums, (http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=1034641&SiteID=1&PageID=1). If you are not interested in your application taking advantage of security and reliability related changes delivered in SP1 version of VC++ libraries, you may just uninstall SP1 and continue using RTM version of VS.Anonymous
April 02, 2007
A reader of the previous post on my blog has posted two questions about using SP1 version of VCRedist.EXEAnonymous
April 06, 2007
First: thank you, thank you, thank you. i've been looking for a workaround to my program not working in other machines despite the redist being installed, and after it was working, it seems because the redist is not compatible with the SP1 of VC++ express. Your instructions are clear and easy to follow. 1 note: i did not find the uuidgen available at the VS command prompt, and had to use: C:Program FilesMicrosoft Visual Studio 8VC>"C:Program FilesMicrosoft Platform SDK for Windows Server 2003 R2BinUuidgen.exe" -n2 it would be good if you added a note to this blog that the redist is not available yet for sp1 VS express (but wouldn;t it be better if the redist was made available together with the development platform?) thank you again MarcosAnonymous
April 06, 2007
>> isn't it possible to automate this procedure completely from the VS environment? >> Yes, VS has setup project that you can use to build a simple MSI. ... is this also available in VC++ Express ?Anonymous
April 14, 2007
The comment has been removedAnonymous
April 25, 2007
Does Microsoft have a place where updated MSM files can be downloaded? On my machine i have one MSM called "Visual C++ 8.0 CRT (x86) WinSXS MSM Beta2", which is version 8.0.50727.42. However, when I build an application, the manifest says it want to use 8.0.50727.762. Is this version available in an MSM file somewhere?Anonymous
May 01, 2007
The comment has been removedAnonymous
May 02, 2007
Hello, Nikola microsoft_vc80_debugcrt_x86.msm in "C:Program FilesCommon FilesMerge Modules" installs C:WINDOWSWinSxSx86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.42_x-ww_f75eb16c. 8.0.50727.42 But what about 8.0.50727.762 DebugCRT?Anonymous
May 03, 2007
Anton, 762 version is VS2005 SP1 version of VC++ libraries. VS2005 SP1 update supposed to overwrite RTM version of MSMs on your computer with the SP1 version of MSMs. If after installing VS2005 SP1, you still see RTM version of MSMs on your hard-drive, something went wrong during install. Heath keeps track of all installation issues with VS2005 SP1 and publishes work around on his blog, http://blogs.msdn.com/heaths/. Check out for example list of known issues, http://blogs.msdn.com/heaths/archive/2007/01/11/known-issues-with-visual-studio-2005-service-pack-1.aspx Usually repair of installation helps to update all files installed by VS2005 SP1. NikolaAnonymous
May 08, 2007
hi I used to work with the vcredist.86 but it is no longer work and i do not know why?Anonymous
May 09, 2007
The comment has been removedAnonymous
July 25, 2007
Hello Nicola, I have to say: All three mentioned methods (statically linking, using this 3rd party tool Wix and this distribution package) are very unhandy even it would work, which means no one of the above methods worked for me. First approach: The Wix method: I do not have an exe called uuidgen.exe. I searched in all my programm folders and in the windows folder as well. I have installed MS C++ 2005 (Version 8.0.50727.762) Second approach: Installing Framework and this redistribution package on the second PC. The error is the same as without installing anything: application configuration is incorrect. My project is a Visual C++ Windows Forms Application. On the PC where the VC++ Express Edition is installed both, the debug and the release exe work. It is a very simple application with a serial port instance to send some data to a controller board. (I didn't intend to give it to anybody but now our customer likes the little prog and wants it without installing VC++) Statically linking: 1>LINK : warning LNK4044: unrecognized option '/MT'; ignored As I would like to give the "uC bord testing application" to our customer aqnd so I would be very happy for any help to get one of these three approaches working. But, as some have mentioned already before: What Microsoft does is a NIGHTMARE! This is the worst thing ever. Developers should spend their time in beeing creative and not in "this administrative stuff".Anonymous
July 28, 2007
Marco, if you're doing anything with C++ you'll sooner or later want the Windows SDK (previously Platform SDK). It's potentially big download but the options can be set so that it's under 200 MB with basic stuff for usermode development. And it should have the uuidgen and bunch of other very useful tools you don't find elsewhere such as graphedit.Anonymous
July 28, 2007
And the VS C++ IDE should also have uuidgen type of tool integrated, look in the menus! Atleast the full version, not sure about Express.Anonymous
July 31, 2007
uuidgen is part of Windows SDK. Now the wix method works and I could run the prog on another pc. Thanks for the hint. I think these steps could be easily integrated in VS C++ Express and would save a lot of people a lot of time.Anonymous
November 16, 2007
Hi Nikola, I try to deploy my VC++ 2005 EE application (window form) in target computer as you suggest (create a msi file). However, my application using DLL files (from OpenCV). Could you pls help me in these questions:
- If my application is window form, do I need to install .NET framework 2.0 in target computer?
- I found the required DLL files in System32 (in developer computer). Do I need to copy them to the System 32 folder in target computer or copy it in the same folder with my exe file? Thanks a lot bro.
Anonymous
November 20, 2007
This is fine if all you want to deploy is "Hello World". What about projects that depend on 3rd party libraries/dll's? Like, OGRE, DirectX, Boost, any game engines, physics engines, etc. MSDN suggests using the XCopy approach. It's a joke, what are we supposed to do? Run around to "everyone's" computer and set up their directory files manually? VS Express really needs SetUp projects included with the IDE. Until then it's just a toy.Anonymous
November 22, 2007
Hello Nikola Very thorough how-to. But I don't really get the point of creating a a custom .msi out of the merge modules unless you've included your own program in the .msi that you end up with. You might as well just distribute the vcredist_x86.exe along with your program then. Either way the consumer has to run two installation files unless you package the two in a setup but then you will have a .msi, a setup.exe and another .msi file and a good chance that the user installs only one of them and expects the program to run. Only reasonable answer to me is file size. I reserve the right to become wiserAnonymous
November 27, 2007
Hello Nikola, Thank you for the solution but I have some problems.. I am using VS.net 2003 so and I have VC++ 7 . everything runs fine apart that I get an while running the light.exe due to that the file policy_8_0_Microsoft_VC80_CRT_x86.msm can't be found. I looked in the location of the merge modules and I found that I don't have such a file. Also I found that I don't have the microsoft_vc80_crt_x86.msm file as well I have another bunch of files listed below: VC_User_ATL71_RTL_X86_---.msm VC_User_CRT71_RTL_X86_---.msm VC_User_MFC71_Loc_RTL_X86_---.msm VC_User_MFC71_RTL_X86_---.msm VC_User_STL71_RTL_X86_---.msm Thank you.Anonymous
January 03, 2008
What have I missed? Installed vcredist_x86, Reinstalled NET Framework2.0. Still no go with an application built in Visual C++ Express 2005, deployed to other computer. "This application has failed to start because the application configuration is incorrect. Reintsalling...." Any help? Anyone?Anonymous
January 31, 2008
I have installed VC2005 installed on my machine. We have our own build scripts which uses VC8 SP1 binaries. When i run the debug executables on my machine it gives the error: "This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix the problem." Any suggestions!Anonymous
March 20, 2008
Thanks for the comprehensive example. I have a minor issue with the msi package size. I'm trying to prepare a msi package for installing the VC80 CRT redists. The merge module size for x86 is about 630 kB, however, the msi package prepared by wix has 2 MB. There is no such problem for x64 CRT redists. The only way I've found for reducing the msi size is setting CompressionLevel for embeded cab to none and then packing the msi with zip, rar, ... Anyone knows any better solution?Anonymous
June 19, 2008
Thank you Nikola, this post saved my day. Really BIG Thank You ! ;)Anonymous
August 12, 2008
This seems to be the definitive page on this topic so thanks for creating and maintaing.
- Why aren't all of the VC6/VC7/VC7.1/VC8 C runtime DLLs installed by default in Vista? Why make the end user or developer jump through hoops to get the program to exectute?
- Can we catch the wrong runtime error programatically and design a dialog that could point to the vcredist download page?
Anonymous
September 18, 2008
I am using the VS2005 and BOOST.... my application is building but i am not able to run the application b'coz of this error :- "This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix the problem."... can anyone help please??Anonymous
October 22, 2008
The comment has been removedAnonymous
November 17, 2008
help please, what is this? "This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix the problem."