MSVCP110D.dll and Visual Studio 2013 - c++

I am trying to run a program I compiled in Visual Studio 2013. However, I get the error
The program can't start because MSVCP110D.dll is missing from
your computer. Try reinstalling the program to fix this problem.
This is not a very helpful error. However, after some Googling, I found that it is (apparently) trying to load a standard c++ library dynamically, and that to get around this I need to specify the /MT option rather than the /MD option. This leaves me with a number of questions:
What exactly is that doing?
What are the benefits of /MD as opposed to /MT? I mean, there must be a reason that it is the default options...
How would I go about getting the looked for .dll and getting Visual Studio to use it? I downloaded this, but honestly don't know exactly how to use it.
Most importantly, how to I get that error to go away and my program to run?
Some additional info: I am compiling in Release mode using an x64 build.

The problem is that you are mixing different versions of Visual Studio by using Qt that was compiled using a different compiler. Remember that each version of Visual Studio will have its own runtime/CRT. The Qt dlls that were compiled with Visual Studio 2012 and will be dependent on the Visual Studio 2012 runtime. They will not use the 2013 runtime.
The solution to this problem is to recompile all of your code and dependent libraries/dlls with the same compiler.
Warning:
Some users will try to just install the dynamic runtime (or recompile dependent libraries with static CRT) from the other version of Visual Studio however this is not a solution to this problem mainly because each runtime has its own independent heap. Having separate heaps can and will lead to random crashes caused by allocating memory in one heap and then trying to free it in a different heap. Since the heaps do not share information about allocations or deallocations this leads to having corrupt heaps. From my experience the problem does not always cause an instant crash. The crash may or may not happen on the next allocation of the corrupt heap so debugging this situation can be very frustrating.

Related

How to leave Visual Studio 2013 dlls dependencies behind?

My application when opened in others computer will give an error missing msvcr"something".dll, I found out that to fix this they need to install the following:
http://www.microsoft.com/en-us/download/details.aspx?id=40784
Which is Visual C++ Redistributable Packages for Visual Studio 2013.
I would like to compile the program with the dlls in the executable already, is such thing possible?
If not possible, where can I get all the dlls to put in the compiled project folder?
Try to set /MT for Release and /MTd for Debug in Project Settings->C/C++->Code Generation. This will make your program not dependent on Visual Studio libraries. But beware that all the libraries/ projects you will link with should also have the same option there, otherwise you'll get nasty linker errors.
You may also wish to select v120_xp in General->Platform Toolset for your program to be able to run on Windows XP
Because a lot of Programms use the functionality of these dll's they are dynamically linked.
So your filesize stays small and in case of fixes within the dll you dont have to recompile your program.
If you dont want this behaviour you can set in the projectsettings the dll's to "static linked" (/MT).
That way they will be compiled into your executable
Here is a relevant MSDN-article
Which is Visual C++ Redistributable Packages for Visual Studio 2013.
For Visual Studio 2013, you need:
http://www.microsoft.com/en-us/download/details.aspx?id=40784
If you were building with Visual Studio 2012, then you would need:
http://www.microsoft.com/en-us/download/details.aspx?id=30679
If you were building with Visual Studio 2012, then you would need:
http://www.microsoft.com/en-us/download/details.aspx?id=5555 (x86)
http://www.microsoft.com/en-us/download/details.aspx?id=14632 (x64)
The point is, you are probably going to need a runtime if you are writing portable C/C++ code by using functions like new, malloc, delete, free, etc.
You might be able to avoid the code if you use the Win32 API. For example, HeapAlloc and HeapFree, etc. Installers often use the Win32 API, and that's one of the reasons they usually don't need a runtime installed prior to running them.
I would like to compile the program with the DLLs in the executable already, is such thing possible?
Yes, its possible. Its called Static Linking (as opposed to Dynamic Linking).
But you will probably still need a runtime.
If not possible, where can I get all the DLLs to put in the compiled project folder?
Retired Ninja gave you this answer: Microsoft Visual Studio ~ C/C++ Runtime Library ~ Static/dynamic linking.
My application when opened in others computer will give an error missing msvcr "something".dll" ...
Another possible solution is to build your project with Visual Studio 2005 or Visual Studio 2008. The runtime used by VS2005 and VS2005 are usually available on Windows Vista, Windows 7, and Windows 8. So the computer may already have them.
But usually you just build your installer to carry around what you need. I use Inno Setup because it allows you to include both x86 and x64 components side-by-side. At install time, you just install the right components based on architecture (x86 vs x64), including the correct runtime. (At the time I choose Inno, Wix did not allow mixing architectures and I wanted a unified installer).

Why won't my C++/Win32 project work outside of Visual Studio?

I have a rather large project I'm working on in C++/Win32, and now that I'm nearing completion, I wanted to start testing it on other machines. My project works great in Visual Studio - either in Debug or Release mode. However, if I try to run either executable from its build directory (with all of the supporting files in place) they crash. I tried using the debug feature provided by visual studio, and it opened malloc.c, saying that a heap has been corrupted. If I had a memory leak or something somewhere, why wouldn't I be getting this error when I run my project from Visual Studio? I could use some pointers on how to debug what the problem might be.
I don't think that is due to memory leak. It has happened to me too when I tried to copy only the compiled executable but not depend libraries. So just check whether all depend libraries are available in other systems too.

Multiple CRTs giving segfault

Background: I'm building a plugin for a large simulation framework. I'm compiling a DLL using Visual Studio C++ 2010.
After much bughunting and googling I believe I have a problem which stems from having multiple versions of CRT linked to my DLL. I'm getting a segfault in tidtable.c (from msvcr100.dll), in the function _CRTIMP PFLS_GETVALUE_FUNCTION __cdecl __set_flsgetvalue(). Reading this thread (there are multiple problems discussed, but towards the end this function is mentioned) is where I got the idea, and if I check the linking part of my project I see msvcr90.dll, ´msvcp100d.dllandmsvcr100d.dll`.
I'm using several external libraries, and I've been able to recompile all but one of them using VS2010. The last one is not open source however (it's a library belonging to the framework), and I guess that is where the dependency would come from. I'm not certain however, how could I check this?
Given that I'm right about where the dependency is coming from, what can I do?
You are linking to the release runtime from Visual Studio 2008 and debug runtime of Visual Studio 2010 ... you shouldn't mix and match release and debug in general. If you need the debug VC9 you'll need to install Visual Studio 2008 (install before 2010 to be safe)
However I'd probably just rebuild all projects and dependencies against VC10. You may be able to get away with installing the redist for VC9 if it's missing from your system for release only.
Edit: Link to Dependency Walker which is invaluable for determining missing or conflicting dependencies.

Can a C++ dll compiled using Visual Studio 2008 be used with Visual Studio 2005?

I'm going to be working with a C++ library written in plain C++ (not .NET and without MFC). The library is available compiled using both Visual Studio 2005 / Intel Fortran 9.1 and VS 2008 / Intel Fortran 10.1.
Obviously I'm going to grab the binaries for VS 2008 since that's the environment on my computer but I'm curious if there are reasons why a straight C++ library wouldn't be compatible between VS 2005 and 2008. I'd assume that the name-mangling would be the same but maybe there are other reasons. I haven't used C++ in a long time so I'm a little rusty when it comes to these things.
It should probably work. The DLL compiled with VS 2005 will be dependent on VS 2005's implementation of the C standard library (msvcr80.dll), whereas your code will depend on VS 2008's C library (msvcr90.dll). This means that at runtime, both versions of the C libraries will be loaded, which is ok, but it increases your memory usage and slows down your load time by a very small amount.
As the other posters have commented, you should be able to work in this way.
However, there is one issue that can be a big one - memory management. The C++ runtimes, in particular, can be tricky.
The biggest issue is that there are some incompatibilities between how the 2005 and 2008 runtimes manage memory. Everything works fine, provided you always allocate your memory in your VS2008 DLL, and always delete the memory allocated from within there within your DLL. This usually requires making some "extra" factory and cleanup methods in your DLL, and exposing these.
If you allocate memory from within your VS 2008 DLL, then delete it from code compiled using VS 2005, or vice versa, you may run into some very difficult to debug problems. It will often work, but have random crashes or instabilities.
The biggest issue you will run into is the usage of the CRT. If the CRT (C RunTime) is statically linked into the DLL, you shouldn't have any issues.
However if the CRT is dynamically linked into the project you may run into trouble. Visual Studio 2005 and 2008 use different versions of the CRT and they cannot easily be loaded togeter. But if one or both of the DLL's statically links the CRT you should be in decent shape.

msvcp80d.dll not found while using TBB

I am using Intel TBB C++ for multithreading an application on visual studio 2008. When I run the executable I get a dialog saying "MSVCP80D.dll" was not found. There is so much on the net about this that it confuses me.
Please help.
EDIT: Based on answers, finally I was able to fix the "dll missing" problem. I had given a path to TBB lib of vc8 leading to dependency on vc8 dlls, which are used with visual studio 2005, not with 2008. (Using depends (http://www.dependencywalker.com/ ) it is easy to determine the run-time dependencies of an executable.) I changed by project to depend on vc9 dlls, not vc8 and then it worked fine.
Another thing to note is use of manifest files on windows. Manifest files describe dependencies. The manifest files must be generated while writing an application as it is necessary.
You can find them online at various places. Just scan it for a virus and put it in your program's path and everything should work fine. You may need more than one of the debug dlls, you can use depends32.exe to see what you are missing.
MSVC80D is VS 2005. As part of VS2008 you would have MSVC90D instead.
Your app is compiled with debug version. Debug version of VC runtime is not in path.
Try to generate release version.
Are you running the program on your development machine? If you are not, you might get this error. The "D" at the end of the filename means that the DLL is a debug DLL, and often not on computers without Visual Studio installed. You're not supposed to redistribute it (copy it around), either. You should compile a "release" version of your application and run that. If you really can't do that for some reason, and it's only one or two computers, then try installing the express version of visual studio on that computer.
If you are having this problem on your development machine, it can apparently be caused by a compiler/linker problem. Try doing a clean build ("clean", then "build" in Visual Studio).
Ok, after a lot of search, and by chance, I landed on this forum http://www.codeguru.com/forum/showthread.php?t=446789 which says something I interpret as "the version of TBB I am using does not support VS 2008".
But this still uncertain.