2

so my code is very simple:

#include "stdafx.h"
#include <iostream>

int main()
{
    std::cout << "Hello World!";
    std::cout << std::endl;

    return 0;
}

thats it. i'm using visual studio 2015. when i'm building the code no errors but when i copy the exe to my win7 vm (no visual studio installed) i'm getting: the program cant start beacuse MSVCP140.dll is missing.... why? i tried to change from debug to release but same error.... why i cant execute this simple code on a win7 without visual studio installed?

kometen
  • 6,536
  • 6
  • 41
  • 51
j.broklin
  • 45
  • 4

2 Answers2

2

You need to statically link to the C++ runtime libraries. That option will be available in your build settings. This causes them to be bound into your executable so they don't need to be present on the machine that's running your program. (The alternative is to distribute the runtime binaries along with your executable but that can be cumbersome).

By the way, writing std::cout << "Hello World!\n"; is often preferable to writing std::endl. See C++: "std::endl" vs "\n"

Community
  • 1
  • 1
Bathsheba
  • 231,907
  • 34
  • 361
  • 483
2

Your Windows 7 virtual machine is missing the Visual C++ runtime dll that includes the functionality you are using in your hello world program, e.g. std::cout. You can download the needed c runtime dll from here: https://www.microsoft.com/en-us/download/details.aspx?id=48145

Patrick
  • 167
  • 3
  • 9