Can Visual Studio 2019 pack the DLLs it requires in just a small .exe file? - c

I made a Windows application with C++ WinAPI by using Visual Studio 2019.
After finishing, I built it, and executed with my computer. It works perfectly.
Then I sent to my friend who didn't have Visual Studio. It said that it needs "msvcp140d.dll" "ucrtbased.dll" "vcruntime140_1d.dll" "vcruntime140d.dll" to open it.
Then I found them in my computer, put them in the same dir with my application, and sent them to my friend. It worked fine, too.
But My question is "Is there any way to pack them with just Visual Studio 2019?" A small application with lots of DLLs is just a little bit weird.

First you're sending the wrong files. Files with d suffix like that are for debugging only and must not be distributed
You cannot redistribute all of the files that are included in Visual Studio; you are only permitted to redistribute the files that are specified in Redist.txt or the online "REDIST list." Debug versions of applications and the various Visual C++ debug DLLs are not redistributable. For more information, see Choosing a Deployment Method.
Determining Which DLLs to Redistribute
Final executable files must be compiled in release mode and use the release version of those DLLs. Don't give out debug binaries. They're seriously slow due to the logics added for debugging purposes
And you don't actually need to send the DLLs but you should tell the user to install the corresponding VC redistributable package. It's the runtime (CRT) for Visual Studio projects containing functions like printf, memcpy... for you. You don't need to find any other DLL if you don't use any DLLs in the project
It's also possible to link the runtime library statically by changing the option /MD to /MT. That way the final exe file will be self-contained (no need for additional runtime DLLs) but it'll also be larger and you lose the ability to use the newer library functions when the package is updated to fix bugs or performance issues. Again, you must compile in release mode regardless of whether you're linking statically or dynamically
See also
Compile to a stand-alone executable (.exe) in Visual Studio
Compile C in Visual Studio 2012 without MSVCRT runtime
How to make a Single Executable VS 2010

Related

Visual Studio Code does not include C header files

I recently downloaded Visual Studio Code to begin learning the C programming language. I installed the program as well as the C extension. However, when I tried to create the "Hello, World!" program, it would not run, and in the Problems menu it did not recognize the stdio.h header file, saying that I need to update my includePath. I have not been able to find any stdio.h file on my computer to link to. Do I need to download the C library files (even though I have read they should be included with the compiler), and if so, where can I find them? Or is there another solution? Thanks, and sorry if this is a stupid question, I am new to this.
I think you might be confusing VS Code with the VS IDE.
VS Code is a source editor only; that is to say that it's basically just a glorified text editor. It has the ability to load extensions and open a shell to compile the code, and there are a few extensions that let you debug the code itself, but they can be tricky to get setup and installed to work well with C/C++ code. VS Code does not have a compiler/assembler/linker nor the requisite headers or SDK's as that is up to you (the user) to install and then point to those in your settings file.
The Visual Studio IDE, on the other hand, is a complete integrated development environment that also includes the system headers and SDK's for Windows, as well as the binaries to properly compile, link and assemble your code into a binary for a Windows system (cross platform is possible as well). The Visual Studio IDE comes in many different flavors with the latest being VS 2017.
If you wish to stick with VS Code, you'll need to grab a compiler and the appropriate header files for the system you're targeting. If you wish to just stick with Windows for now, you can grab the Windows 7 SDK here or the Windows 10 SDK here .. you could even grab both and just reference the one you wish when you want. Note that the Windows 7 SDK includes the Microsoft C/C++ compiler, alternatively you can download the MSVC compiler from their Build Tools site.
There's also Cygwin in which you can use the GNU compiler, and of course Clang, which can be referenced in both VS Code and the VS IDE.
I hope that can help.

Visual Studio 2013: C Application on any Windows version

The situation
I have an app created in Visual Studio 2013 written in C. It work flawlessly on my computer (Windows 7) and on other Windows 7 computers that I have tested the app on.
The Issue
In order for my app to work, Microsoft Visual C++ Redistributable has to be installed otherwise a couple of other .dll files are needed (MSVCR120.DLL for example). When I tried this on Windows XP I confronted with the following error:
C:\path\to\app.exe is not a valid Win32 application
and found no way of solving that.
The Question
How can I solve all the problems and have a single .exe file that works on any Windows system regardless of its configuration without the need of extra files or an installer?
Bonus Question
What are these MSVCR***.dll files?
You can statically link to the vc runtime and that should eliminate the need for installing dependencies. Note that the .exe will be larger because the dependencies are compiled in.
Set /MT for Release and /MTd for Debug in Project Settings -> C/C++ -> Code Generation
You can also set v120_xp in General -> Platform Toolset for your program to be able to run in Windows XP (http://supportxpdotcom.wordpress.com/2013/07/16/xp-targeting-support-in-the-visual-studio-2013-preview/)
The MSVCR*** files are C run-time library files that hold the functionality for C run-time functions used in a program. When you statically link a program, you compile them in to the .exe and so don't have to distribute them separately. (http://msdn.microsoft.com/en-us/library/aa272081(v=vs.60).aspx)

MSVCR120.DLL Required

I was asked to download the specified DLL after running one of my apps on a secondary computer. The only problem is whether or not it should have been required. I obviously code in Visual Studio, but it is in pure "C" and a Win32 project, so I'm just wondering if this is normal.
if you don't want to load CRTs, change run time library to static library. (MT)
or you need these dlls in installed visual studio\VC\redist
//after your comments//
MSxx##D.dll D means Debug.
if you link any library built with debug run-time, the exe needs debug runtime library

Package C console application (Visual Studio '13)

I wrote a basic program for my mom, and now I want her to be able to use it. Obviously, it works on my computer. Getting the .exe file from the project folder, and putting it on her computer doesn't work: it says MSVCR120d.dll is missing whenever the .exe is run. Makes sense--as her computer doesn't have Visual Studio on it. However, I tried installing the Visual C++ Redistributable Packages for Visual Studio 2013, and that didn't work either.
To be honest, I'm not looking to spending hours of time to piece this all together. This is something I will more than likely never do again--I've already done some searching and can only find subjects speaking of C++ distributions. I want a way to get the console app on her computer to work.
The more easy way is link statically. That mean embed all the needed code to the app to run, in the final binary (.exe), eliminating dependency of other libraries.
Go to Project Properties
Go to Configuration Properties
Go to C/C++
Go to Code Generation
Change Runtime Library (in Debug to Multi-Threaded Debug /MTd and in Release to Multi-Threaded /MT)

How to solve this MS runtime DLLs loader runtime error (R6034)

Here is my situation:
I have a C project linking with many libraries (I haven't written this application), and it is shipped also with MSVCR71.dll and MSVCP71.dll. Even without those DLLs, the program has run fine on my system, which has MS VS2005 installed (indeed uses MSVCR80.dll and MSVCP80.dll).
I've linked this application with other libraries, compiled on my system. Now, after having linked with those libraries, the application don't start because it cannot load MSVCR80.dll and MSVCP80.dll... very strange, I say.
Loader presents to me the error R6034, which should be solved building applications using the manifest file.
What's wrong with this application?
Confirm that the problem was introduced by the libraries introduced. May I compile those libraries without manifest or statically?
Still curious why application without linking new libraries don't find MS runtime DLLs...
MSVCP71.dll is a dll used by Visual Studio 2002. MSVCR80.dll is for Visual Studio 2005.
So, when you recompiled this app with VS2005 you got new dll dependencies.
You cannot solve it with manifests - you should recompile it in Visual Studio 2002 or just put these new dll's into the same folder where you app is located.
Edited:
And yes, you can just link your application with static CRT libraries to avoid external dependencies on these dll's. But it may be not possible if one of dll's or libraries that you link with uses dynamic CRT - you should recompile them also with static CRT then.

Resources