Running .exe without copying .dlls - c++

I have Visual Studio 2015 solution ready for delivery. I have a requirement that the .exe should run out of the box. However, I am getting "missing dll..." errors. Is there any way I could make it possible for someone to run the exe without him needing to download bunch of ddls? Can I build the .exe to be executable as stand-alone somehow?

Yes, you have to statically link the binary. In the project settings (Configuration Properties -> C/C++ -> Code Generation), use /MT, /MTd for the Release, Debug configurations respectively. However, this bloats the size of the executable.
MSDN documentation on /MT, /MTd options

Related

How to get rid of Debug runtime DLLs

I am using a VS2015 to create DLLs which will be used in a project (which will be run on another PC).
I have build the DLLs in Release version on my PC but when I start the project on another PC, I get following errors:
VCRUNTIME140D.dll is missing
MSVCP140D.dll is missing
MSVCP140D.dll is missing
What steps should I take while creating these DLLs so that these debug runtime DLLs won't be required to the run the project on any PC.
In spite of it being built in release mode, if you require "...D.dll", then there are debug builds in the mix.
This could be the result of the third party dll you have or there are DEBUG or _DEBUG defines floating around.
Most likely is that the build (of the dll or the host exe) is explicitly set to use the debug version of the runtime (/MDd). Change this in the project settings to not use the debug version of the runtime (/MD).
Open the project's Property Pages dialog box.
Expand the C/C++ folder.
Select the Code Generation property page.
Modify the Runtime Library property.
To assist in the diagnosis of which binary is responsible for the debug dependency, you can use Dependency Walker to track down the offender. It will give you a list (as a tree) of the dependencies of each file.
In general, for missing the C++ runtimes (release version) on a target machine, you should install the C++ redistributable. As of this writing, VS 2015 redistributable is available here.
In C/C++ -> Code Generation -> set Runtime Library to:
Multi-threaded Debug (/MTd)
And yes, such setting is very much needed if you want to debug a process on a remote machine. So, don't go by others saying, "test with Release build only". Obviously, you'll need Remote Tools installed.
As stated by Niall, you should use dependency walker in order to find which part of the project is causing the error, it might not be the dll in issue after all.
My bet is it's just some part of the project you forgot and built in debug mode, which of should never be used for production as debug dlls are not included in C++ redistrib installers.

C++ MSVCP120D.DLL is missing

I am using visual studio 2013 and I build my project under release. However when I try to execute it on another machine without visual studio but with vc_redist installed, I get the error: msvcp120d.dll is missing from the computer, which is used when a project is compiled in debug. Any way to solve this problem?
You need to change settings in Project properties
Right click on your project > Properties > C/C++ > Code Generation
and inside you have to change Runtime Library from Multi threader DLL (/MD) to Multi Threader (/MT). This way you won't need to include additional libraries with your build.
First check that all your projects are actually set to build in Release.
You do this by opening the 'Configuration Manager' from Build -> Configuration Manager...
Select Release and Win32/x64 whatever you are building and then ensure all your projects are set to Release configuration.
If they are all fine then you will need to either manually check the Project settings for each project, or you can use an application such as Depends to help find the offending EXE or DLL.
http://www.dependencywalker.com/
I just installed both vcredist_x86 and cvredist_x64 and it works.

Static lib links, c++, VS Express 2013

Ok so I made a small multithreded program in c++, when I compile it on one machine it works fine but when I try to run it on another machine it says "missing msvcp123D.dll".
I went looking around the forums and found some good info on this one. The solution was to create static links to the needed libs.
Project Properties -> General -> Use MFC in a Static lib
Project Properties -> Input -> additional dependencies -> ? now I would like to ask what libs do I need to add here in order to make this work on Windows 7 , 8, 8.1 machines
Thank you all for your time.
msvcp123D.dll is the DEBUG runtime. Build a release version and install the VC2013 redists on the target machines to get rid of this error.
Alternatively you can statically link the run time in which case you'll just need your own binaries (even if its a debug build).
Edit: To statically link the runtime right click the vcxproj file and go to properties, then under C/C++ code generation change "Multithreaded Release/Debug DLL" to "Multithreaded Release/Debug". The options with out "dll" in the name are the static versions.

How to not link against msvcr100.dll?

I am compiling project in Visual Studio 10, compiled executable runs fine on win 7 but it doesnt works on win xp because of missing msvcrt100.dll.
I tried to use "/NOTDEFAULTLIB" but it also removes some other external libs that i use.
Is there way to not link against latest Microsoft runtime library ?
Thanks in advance.
To not link against the DLL you must link against the runtime statically.
To do this, go to C/C++ Properties -> Code Generation and under Runtime Library select Multi-threaded (/MT) or Multi-threaded Debug (/MTd) from the drop-down. Note, once you're using a static runtime library all of your other library code you link against must also be built with the same setting. And you will also likely have to add additional libraries to the Linker -> Input under Additional Dependencies.
It only works on Windows 7 machine by accident, somebody installed that DLL earlier.
Short from creating an installer (easy to do with a Setup project), a simple fix is copying msvcr100.dll along with your own binaries. If you only have an EXE then the simple solution is to link the static version of the CRT. Switch to the Release build, right-click the project, Properties, C/C++, Code Generation, Runtime Library setting. Change it to /MT from the default /MD.

A C++ Application Compiled With VS2008 Doesn't Run In Other Computer

I have created a wn32 project with Visual Studio 2008 and Visual C++ language, it uses the ws2_32.lib library and then I compiled in Release mode.
It runs very good in the same computer, but when I copy the exe file to other computer (that doesn't have installed Visual Studio), it doesn't run.
The message I see is:
This application has failed to start because the application configuration is incorrect. Reinstalling the application may fix this problem.
But, if I compile my application using DEV C++, it generates a bigger executable (738KB) compared with the Visual Studio 2008 executable (9.5 KB). However, the DEV C++ executable runs in the other computer.
I have add the library ws2_32.lib to the linker properties of my project, in the Additional Dependencies field.
How can I fix it to work with Visual Studio 2008?
My code is the following: http://www.stan.com.mx/yupi/udpserver.cpp
The problem is almost certainly that the other computer does not have version 9 of the C++ CRT installed.
The default setting for compiling against the CRT in VS2008 is to dynamically link vs. statically linking. If you want to deploy your program with a real setup project you'll need to include the CRT redistributable.
However if you want to do an XCOPY deployment follow the steps on the following page.
http://msdn.microsoft.com/en-us/library/ms235291.aspx
Try installing the Visual C++ redistributables. If that doesn't work, use DependencyWalker to find out what DLLs are missing.
I agree with JaredPar. The application you build with VS2008 is using dynamic linking, whereas the DEV C++ is linking statically, hence the larger size and why one works and not the other.
However, if its a plain win32 application project you've got (and you don't want/need to distribute it with a setup), you may be able to get it to run on another machine without redistributing the CRT by getting VS2008 to link statically for you (if its just the standard lib you're missing). I don't have a copy of VS2008 to hand, so I'll describe how to do it in VS2005 and hopefully it'll translate across.
Bring up configuration properties for the project (right click the project name, then select "properties" from the menu)
Expand "Configuration Properties", then "C/C++", then click "Code Generation"
Under the "Runtime Library" item, for your particular configuration select the non-DLL version of the library i.e. for debug builds you want "Multi-threaded Debug (/MTd) and for release builds you want "Multi-threaded (/MT)"
Try and see if that works. You'll obviously get a much bigger final binary now the library is statically linked.
You may be missing an external dependency required by your program. Check the project settings to see if you are linking against MFC dynamically for example. You can also run Depends utility to check for missing dependencies.