0

Every time I write a C program using Visual Studio 2013 the .exe file only runs on my PC. When I copy that .exe file to other PC it doesn't run. But if I use Code Blocks IDE instead the .exe file runs in all PCs. Why? and how can I make a 'C program' written in 'Visual Studio 2013' run on every PC?

  • I'm certain this has been asked and answered here many times before. 1. make sure you compile *release* mode 2. install any prerequisite runtime libraries – crashmstr May 22 '15 at 16:58
  • [Related 1](http://stackoverflow.com/questions/5936724/how-to-redistribute-vc-application-from-visual-studio-2008), [Related 2](http://stackoverflow.com/questions/11498888/visual-studio-2005-exe-file-not-running-on-another-computer), [Related 3](http://stackoverflow.com/questions/99479/visual-c-studio-application-configuration-incorrect), [Related 4](http://stackoverflow.com/questions/27104870/running-visual-studio-release-build-exe-file-in-different-machines), [Related 5](http://stackoverflow.com/questions/10072725/c-program-works-on-xp-sp2-only-after-installing-visual-studio) – crashmstr May 22 '15 at 17:02
  • [Related 6](http://stackoverflow.com/questions/2971918/unable-to-run-native-c-application-on-different-machine) – crashmstr May 22 '15 at 17:05

2 Answers2

3

It's because of the 2013 runtime libraries1, you need to download the redistributable and install it into the target computer.

You can download it from here.


1The file is called msvcr120.dll if you compiled with the VS 2013 ("v120") platform toolset, and otherwise follows the pattern msvcrNNN.dll.

MooseBoys
  • 6,641
  • 1
  • 19
  • 43
Iharob Al Asimi
  • 52,653
  • 6
  • 59
  • 97
  • You can also statically link against the runtime libraries by specifying this in `Project Properties > C/C++ > Code Generation > Runtime Library`, which can simplify deployment (you don't need to install the redist) but also bloats the executable's size. – MooseBoys May 22 '15 at 17:00
0

In your project settings, change the Runtime Library support to Multi-threaded (/MT) instead of the default, which is Multi-threaded DLL (/MD). This will cause your .exe to be statically linked, and it won't need to look for the runtime libraries on the target machine. (I think it's under C/C++ Code generation, but I don't have visual studio 2013 installed at that moment to verify that).

The resulting .exe will be bigger (because it has to link in all the parts of the runtime that you use), but it simplifies deployment on other machines - no need to install the redist package.

Jeff Loughlin
  • 4,134
  • 2
  • 30
  • 47