1

I have recently written a fairly simple code for windows app, a 2048 game, including some basics such as icon, background and stuff, 4 buttons for different directions and 4x4 array of static windows for output. The Code isn't really "nice" but as I'm still learning I find it enough since it work ( at least on my PC ). I'm using default VS13 config, haven't changed anything after I installed it and the code is written in c++. Codes can be found here: https://www.dropbox.com/sh/15y1daq2h3jm8p7/AADp0m1EfUJo3W2z315Zgd0Wa

Now what bugs me is that the program compiles with 0 warnings or errors and works just as I intended it when I run it either via debug or from desktop on my PC, but when I upload it to dropbox and want to start lets say on laptop then it doesn't work. Also if I try to compile the exact same code in Codeblocks I can't and there are warnings that many functions weren't declared in the scope. Can any1 explain why is this happening and how can I fix it ?

Survaf93
  • 162
  • 1
  • 11
  • 1
    Could you share the exact errors? – Sunny R Gupta May 08 '14 at 06:35
  • Missing msvcp120d.dll is the first error then after I downloaded that one it just says that my app isn't a valid win32 application. – Survaf93 May 08 '14 at 06:36
  • 1
    Do you have VC++ runtime redistributable installed on the laptop? – LeleDumbo May 08 '14 at 06:38
  • I'm not so much into programming to know things like that, did you mean VC++ redistributable for VS13? I just downloaded it and installed and still the same error (0xc000007b). Well now it says the app wasn't able to start correctly. – Survaf93 May 08 '14 at 06:45

1 Answers1

0

The basic problem you are facing is that you are trying to compile the code outside of the Visual Studio environment for a VCPP code that you have written.

When you debug the code using Visual Studio, all the required files/dependencies are injected during compilation.

I'd recommend packaging the code using Visual Studio and try running the exe on your laptop.

Make sure you have the correct version of VC++ runtime environment installed on your target machine. (You can optionally also include the setup with your packaged setup.)


From here: https://stackoverflow.com/a/20890610/1477051

As you can see here, the MSVCP DLL is the platform's implementation of the C++ Standard Library. In short what that means is you cannot distribute your application without needing the "stuff" that these libraries provide. All compilers regardless of platform would need some kind of implementation of the Standard Library. Typically this is distributed in the form of libraries.

However you can distribute your application so that the "stuff" is built in to your program directly, rather than being shipped in a separate DLL. In order to do this, you must statically link your application to the Standard Library.

There are a few ways to accomplish this. One way is in Project Settings. In "Configuration Properties" > "C/C++ Code Generation" > "Runtime Library", choose "Multithreaded (/MT)" as opposed to "Mutithreaded (Static)".

By the way, the "D" in "MSVCP120D.dll" you mentioned above means "Debug." This means that you are trying to distribute a debug build of your program. You should (almost) never do this. Distribute release builds instead.

Community
  • 1
  • 1
Sunny R Gupta
  • 5,026
  • 1
  • 31
  • 40
  • Wow, ok now I learned something really useful thanks, but now I am getting an error in a file I never even heard of any chance you can assist me with this? I've changed the Runtime Library to /MT – Survaf93 May 08 '14 at 06:54
  • 1>------ Build started: Project: w2048, Configuration: Debug Win32 ------ 1> 2048Main.cpp 1>libcpmtd.lib(stdthrow.obj) : error LNK2019: unresolved external symbol __CrtDbgReportW referenced in function "void __cdecl std::_Debug_message(wchar_t const *,wchar_t const *,unsigned int)" (?_Debug_message@std@@YAXPB_W0I@Z) 1>c:\users\admin\documents\visual studio 2013\Projects\w2048\Debug\w2048.exe : fatal error LNK1120: 1 unresolved externals – Survaf93 May 08 '14 at 06:55
  • Setting compiler flag /MTd (multiThreaded debug runtime library) will solve the problem. – Sunny R Gupta May 08 '14 at 08:07
  • You are building a "debug" configuration. Debug configurations run only on a machine with Visual Studio installed. Build a "release" configuration when using /MT and to be able to run the program on other machines. – ScottMcP-MVP May 08 '14 at 13:20
  • 1
    I did, but I have to ask what's the difference between release and debug configs ? – Survaf93 May 08 '14 at 21:26
  • By default, Debug includes debug information in the compiled files (allowing easy debugging) while Release usually has optimizations enabled. – Sunny R Gupta May 09 '14 at 07:26