What DLLs to add to my Visual Studio 2017 project? - c++

I have a C++ project compiled on Windows 8.1 that doesn't work on some computers. On another Windows 8.1 machine it doesn't open because it's missing a DLL file api-ms-win-core-*. On Windows 7 machines it crashes with a BEX error.
I link dynamically against the runtime library (Multi-threaded DLL (/MD)) and include the following DLLs in the same folder as my executable:
msvcp140.dll
ucrtbase140.dll
vcruntime140.dll
Is there anything else I should include?

Related

Windows Subsystem for Linux - Include path for Visual Studio 2019 IntelliSens

Apologies if this is trivial.
I am working on a C++ project using Windows Subsystem for Linux. There is no issue compiling and debugging the project, but IntelliSense does not see the libraries I have installed and gives me a lot of warnings/errors:
Where is the lib folder for Windows Subsystem for Linux?

The loading order for unmanaged C++ assemblies ( specifically VS C++ 2015 redistributables and Universal CRT)

This is similar to the question here, but it pertains to the unmanaged C++ assemblies, instead of managed .Net ones.
Assuming that my application directory has its own Visual Studio Redistributable 2015 runtime DLLs ( I redistribute the runtime at app directory, just in case the client machine cannot install the VC++ redistributables from Windows update), and the client machine also has Visual Studio Redistributable 2015 package installed. Which one will get loaded, the vcruntime140.dll located at the application directory, or the vcruntime140.dll installed?
Similarly, my application directory has its own set of Universal C Runtime ( Again, I do this out of the reason that some client machines cannot install Universal CRT due to various reasons), and in the case the client machines also have Universal CRT installed, which one will get loaded, the installed Universal CRT DLLs, or the ones at my application directory?
For Windows 10 and Universal CRT, I know that the Universal CRT in the system directory is always used, even if an application includes an application-local copy of the Universal CRT. It's true even when the local copy is newer, because the Universal CRT is a core operating system component on Windows 10.
But I am not sure about other Windows 10, and above Visual Studio C++ redistributable package.
Thus I am looking for answers on all supported Windows versions, including Windows 7, Windows 8.1 and Windows 10.
Note: I am calling the unmanaged C++ assemblies from .Net, if that matters.
The load order for your CRT dll's are in the following order:
Directory from where app was started
Current directory
System directory
Windows directory
Path environment variables.
You can place your runtime dll's in the app's current dir, and they should load. If you are compiling on Windows 10 and don't want UCRT refrences, compile with /NODEFAULTLIB
Or, you can statically link to the CRT libraries using the compile option /MT

Exception: FILE NOT FOUND - Deploying C++ app on windows server 2008 R2

The Problem: C++/CLI application is throwing file not found exception on windows server 2008 R2 because msvcr120.dll is not available in system32 folder. Instead, there is file with name msvcr120_clr0400. Vc++ 2012 update 4 and .net framework 4.5.2 is installed on windows server.
Exception Details:
a few details of exception:
Problem Event: CLR20r3
Problem Signature 8: 124
Problem Signature 9: file not found exception
Application build configs:
visual studio 2013x86release.net 4.5vc++ 2012
Dependencies: checked from dumpbin utility
kernel32.dll
MSVCR120.dll
MSVCP120.dll
mscoree.dll [ from windows/system32 folder ]
opencv dlls and some other dlls - resides in exe folder.
Now, my Questions are that
is there any difference between deploying c++ application to windows server and on other end-user windows editions?
should I install Vc++ 2012 [without update] as well?
It sounds like the wrong version of Visual C++ Redistributable Package. Depending on your opencv version I think you need a different version vcredist.
Edit:
msvcr120.dll is part of Visual C++ Redistributable Packages for Visual Studio 2013 microsoft.com/en-US/download/details.aspx?id=40784

How to fix error MSVCP120D.dll in Visual Studio 2015?

Hello I have downloaded and unzipped OpenCV-2.4.10.exe on my PC. Then created a new Win32 Console application project in VS 2015, set all the Paths in Project properties, set the environmental variables in Win8.1. When I'm trying to start the program in debugging mode I get the "The program can't start because MSVCP120D.dll is missing from your computer. Try reinstalling the program to fix this problem".
Then, I downloaded the Visual C++ redistributable for Visual Studio 2015 But the problem still remains. What should I do to use OpenCV in VS 2015?
OpenCV-2.4.10.exe comes with runtime binary dlls built to work with runtimes from vc10 (vs2010), vc11 (vs2012) and vc12 (vs2013).
These DLL files use MSVCP100.dll, MSVCP110.dll and MSVCP120.dll respectively, and if you have installed Visual Studio 2015 you should find them in your System32 (or SysWOW64) directory.
The MSVCP120D.dll error appears when your application tries to load the DEBUG version of the DLL binaries. You do not have MSVCP120D.dll unless you have Visual Studio 2013 installed on your system. To solve this problem, use the Release runtime instead of the Debug runtime.
All you need to do is exclude the DEBUG lib files from your project. This means including only the lib files without the suffix 'd'. (ie. include opencv_core2410.lib instead of opencv_core2410d.lib)
HTH
Extras:
You don't really need to load the Debug binaries, unless you need to debug openCV's source code. If you do, there's still a way. Download the openCV source code, use CMake to create a VS2015 project. You can then build your own dll binaries using the latest runtime from VS2015.
VS2015 uses vc14 while OpenCV2.4.10 doesn't come with pre-built binaries associated with vc14. This answer should help you to understand. Accordingly you should choose the right folder (vc14) for Linker>General>Additional Library Directories in project properties.
You can use cmake to build binaries using VS2015 or you can download a later version of OpenCV which has prebuilt binaries for vc14.

C++ custom installer (launcher)

I have written a portable program in C# with certain dependencies (.NET Framework, Visual C++ redistributable, etc) that will run on Windows XP SP3 and up.
Because of that, the program needs a launcher that will run every time before the actual program does, checking that all the required dependencies are installed. If any of the dependencies are missing, an option to download and install that dependency, will be offered. If there are no missing dependencies, then the actual program is executed.
The launcher itself is relatively simple, consisting of some registry checkup and some WinAPI calls to verify the installed dependencies.
The file structure in the end will look something like this:
C#_compiled_portable_program.exe
C++_compiled_launcher.exe // executes on any system as low as a clean Windows XP SP3 install
The problem is that I have no idea how to compile a C++ code in Visual Studio 2013 that will run with absolute bare minimum dependencies (running on the runtime libraries that come with Windows XP SP3, at least).
Take for instance the absolute simplest C++ code:
#include "stdafx.h"
int _tmain(int argc, _TCHAR* argv[])
{
printf("Hello world!");
return 0;
}
If I compile this with Visual Studio 2013 with the default configurations, it will not execute on a machine that doesn't have VC++ 2013 installed, showing some nasty errors.
I looked around for similar questions and the closest I could find was
Visual Studio 2010 MSVCR dependency removal?, but the answers are either incomplete or outdated.
So, just like an installer, is it possible to compile a C++ project in Visual Studio 2013 that will run pretty much on any system?
This is not perfect, but will do for now.
This is what I did to make a C++ project, compiled in Visual Studio 2013, execute ona system that doesn't have VC++ 2013 installed.
I created a new C++ project in Visual Studio 2013, File>New>Project>Visual C++>Win32 Console Application
Then in Solution Explorer right click the project and select Properties.
Click the Configuration drop down menu and select All Configurations.
In Configuration Properties>General, set Platform Toolset to Visual Studio 2013 - Windows XP (v120_xp).
With Dependency Walker determine what modules are imported by the compiled exe (the release build, not the debug one). The imported modules should be:
c:\windows\system32\KERNEL32.DLL
c:\windows\system32\MSVCR120.DLL
KERNEL32.DLL is a system file so we don't have to worry about that, and MSVCR120.DLL is the Visual C++ 2013 Runtime Library and we need to distribute this file along with the release build. When the executable needs to load a module, it first looks at its current location for that file and then in PATH (System32, etc). If we copy MSVCR120.DLL at same location the release executable is, then the program will run even on systems without VC++ 2013 installed.
Since the project is a 32-bit application, download VC++ 2013 Redistributable x86, install it on a 32-bit version of Windows (I installed it on a fresh Windows XP virtual machine), and copy c:\windows\system32\MSVCR120.DLL.
Update:
Never mind. You don't have to distribute a copy of VC++ Runtime DLL file, you can just configure the project to link statically to the runtime library.
Here is explained how to do it. You'll still have to change the Platform Toolset though, if you plan on executing on Windows XP.