如何运行我在另一台计算机上编写的 c 程序 [英] How to run a c program i wrote on another computer

查看:17
本文介绍了如何运行我在另一台计算机上编写的 c 程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个程序并使用 Visual Studio 2017 对其进行了编译..exe 文件在我的 PC 上运行没有问题,即编译它的那个,但是当我将 .exe 文件,甚至整个文件夹不同的机器,它不会工作.

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.

首先,我尝试处理整个文件夹,包括 .c 和 .h 文件;另外,我尝试下载 Visual Studio 的扩展,它允许我创建一个 .msi 安装文件,它也没有太大变化.

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

根据我所做的研究,问题的主要原因是缺少适当的 c++ 可再发行文件.我的主要问题是这个程序是为一家小公司编写的,让他们安装额外的软件对我来说是个问题.有什么办法可以在不让他们安装额外软件的情况下解决这个问题?我可以通过在 .exe 文件中包含更多文件来以某种方式解决此问题吗?

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?

推荐答案

几乎所有使用 Visual Studio 2015 或更高版本构建的 CC++ 程序都会在具有相关 VC Redistributable 已安装.

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.

不过,这意味着创建一个Setup.exe"文件来运行 .msi 包.要使用此方法,请在解决方案资源管理器"中右键单击.vdproj"项目,然后单击先决条件"按钮.(如果未启用此按钮,请务必在属性页的左上角选择您的发布"配置之一.)

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.)

单击此选项时,请确保选中先决条件"对话框顶部的创建安装程序..."复选框,然后向下滚动并选择相关的Visual C++ '14' 运行时库"选项(每个支持的平台一个).[注意,虽然它们被称为 VC '14',但它们都适用于 14 以上的任何 VC 版本!]

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!]

然后您必须分发Setup.exe"程序您的.msi 包.当他们双击Setup.exe"时,它将检查并在必要时下载并安装可再发行组件.

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.

还有另一种方法可以做到这一点,即在安装包中包含相关的、特定于平台的可再发行组件,然后从安装程序中将其作为自定义操作"运行.但这不是微不足道的!如果您选择走这条路,我可以发布一些示例代码.

这篇关于如何运行我在另一台计算机上编写的 c 程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆