Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

visual studio - How to run a c program i wrote on another computer

I wrote a program and compiled it with Visual Studio 2017. The .exe file runs with no problem on my PC, the one on which it was compiled, but when I take the .exe file, or even the whole folder to a different machine, it won't work.

First of all, I tried coping the whole folder including the .c and the .h files; also, I tried downloading an extension for Visual Studio which allows me to create a .msi installation file, which also didn't change much.

The error messages I get are the following ones:

the code execution cannot proceed because ucrtbased.dll was not found
this code execution cannot proceed because vcruntime140.dll was not found

From research I did, the main reason for the problem is the lack of appropriate c++ redistributable files. My main problem here is that this program was written for a small company, and its problematic for me to make them install additional software. Is there any way of solving this without making them install additional software? Can i somehow fix this by including more files with the .exe file?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Almost all C or C++ programs built with Visual Studio 2015 or later will only run (properly) on PCs that have the relevant VC Redistributable installed.

You say you don't want folks to have to install something else - but, one way or another, they will have to. However, as you are building an install package, you can probably set the relevant redistributable as a "prerequisite" in that installer.

This will mean creating a "Setup.exe" file to run the .msi package, though. To use this method, right click on your ".vdproj" project in the "Solution Explorer" and click the "Prerequisites" button. (If this button is not enabled, then be sure to select one of your "Release" configurations in the top-left of the property page.)

When you click this, make sure you check the "Create setup program to …" check-box at the top of the "Prerequisites" dialog, then scroll down and select the relevant "Visual C++ '14' Runtime Libraries" option (one for each supported platform). [Note, although they're called VC '14', they will each work for any VC version from 14 upwards!]

You will then have to distribute both the "Setup.exe" program and your .msi package. When they double-click "Setup.exe," that will check for and, if necessary, download and install the redistributable.

There is another way to do it, by including the relevant, platform-specific redistributable in your install package, then running that as a "Custom Action" from the installer. But this isn't trivial! I can post some sample code for doing this, if you elect to go down this road.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...