C++ program not running on windows systems without VS installed “VCRUNTIME140.dll was not found”

和自甴很熟 提交于 2020-07-03 05:29:06

问题


When I compile a simple program:

#include <iostream>

using namespace std;
void main() {
    cout << "Hello world!";
}

And tun the compiled .exe on another system without visual studio installed I receive the following error:

The Code execution cannot proceed because VCRUNTIME140.dll was not found. Reinstalling the program may fix the problem.

When I compile with cl.exe I receive no errors, does anyone know a workaround to this without installing VCRUNTIME140.dll on the systems. (I've tested on multiple windows systems including a windows virtual machine)


回答1:


Get the "Visual Studio 20xx VC++ Redistributable package" for your version of Visual Studio. Then run on the target machine to install.

Bottom of this page: https://visualstudio.microsoft.com/downloads/

Or bottom of this page for older versions of Visual Studio: https://visualstudio.microsoft.com/vs/older-downloads/




回答2:


I've encountered this problem before and there's a simple solution to it,

The missing .dll are a issue of static linking not missing packages (in most cases), becuase visual studio 2019 comes pre-installed with what you need.

To fix: go to your project properties (in project tab) Select C/C++ Change the value of runtime library to "Multi-threaded debug (/MTd)"

This will cause the compiler to embed the runtime into the app. The executable will be significantly bigger, but it will run without any need of runtime dlls.



来源:https://stackoverflow.com/questions/59494854/c-program-not-running-on-windows-systems-without-vs-installed-vcruntime140-dl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!