Compile program in VS without any need of external runtime dlls - c++

This is somewhat an addition to this question (MSVCP140.dll missing).
I am trying to compile a program for a windows machine. Something huge to note here is I do not have the privileges to install software on it, but I may run executables.
Every time I run it on the windows machine in question I get a missing MSVCP140.dll problem. I have followed the solution of the question I have linked (which is static linking) and for some VERY odd reason I am still getting the error (even though I know this enabled the program to run on colleagues computers when they were getting the same error).
Is there anything more I can do that will make the program (for lack of better terms) fully portable? Any more settings I need to change in VS such that it will fully compile the libraries into the executable?
I am going to further stress the fact I have seen the solution to use static linking using the /MT option for compilation and I am still getting missing .dll problems.
I tried copying MSVCP140.dll next to my executable and it did solve the issue, but there is another missing .dll and I cannot incrementally add .dlls until the program starts working. I am happy to bundle all the .dlls with the program if that is the only solution but I would like to know which ones are needed so I don't have to copy my entire system32 folder out of desperation.

Have a go at using dependency walker to figure out what dlls you need, and why you need them. This can be enlightening, and lead to a path of cutting out many dependencies by using alternatives. If you are sure you aren't importing certain functions at consumer runtime (e.g. you are only importing them for debug purposes), then you can choose to delay load them.

Related

MSVCP140.dll despite /MT runtime library setting

I tried to run a program I wrote on a remote computer. As I knew there might be a dll problem, I set the runtime library option to /MT, so I can rely on static linking.
However, I still receive the error message on my remote computer, stating that MSCVP140.dll is missing. Isn't this what the /MT flag should take care of?
I even tried to install the redistributable, but no luck. I'm still stuck with the error.
Another thing I tried was placing a MSVCP140.dll I downloaded in the folder, but that way my program is simply crashing on startup. I suspect that the MSCVP140.dll version is not the expected one, so I'm not relying on the validity of this test.
Any ideas?
Try to open your exe with depends.exe and find the dependancies in the machine it crashes. Probably the MSVCP140 might have other dependancies. Copy all dependancy dlls into same folder and give a try.
Someone please punch me for being this stupid... I was compiling on x86 instead of x64 all the time. No surprise the dlls didn't work.
Thanks for the help nevertheless. At least you got me on track to take a closer look at my dlls.

The required DLLs in a visual studio c++ project

I've done some searching and seen questions similar in nature to mine, but none that quite hit the nail on the head of the issue I'm having.
I'm making C++ game in Visual Studio (with the Allegro 5 library) and encountering difficulty running it on other computers. I'm well aware of the 'MSVCR##.dll is missing from this computer' issue, but what I'm wondering is why I'm unable to run my Release build because I'm missing the MSVCR##'D'.dll on a certain computer, when I was under the impression that the 'D' suffixed .dll was exclusively required for running the debugger. I've checked in my configuration manager for release build settings and I have 'Generate Debug Info' set to No, which I thought was the only thing I needed to do. My question I guess is whether or not there are any other settings I need to configure to make sure my Release build isn't looking for the MSVCR##D.dll. Thanks in advance anyone who has any info!
You're a bit confused about the use of the *D libraries. They're indeed used for debug builds, but debug builds differ in multiple ways from release builds. For starters, debug builds by default come with a *.PDB file that contains all the function names (This is your "Generate Debug Info" option). A debugger looks into the .PDB file to find a readable name for a crash site.
Another debug option is to not inline code - this keeps your named functions intact. Inlining may put that single finction inside three other functions, which complicates debugging a bit.
Finally the Debug CRT includes functions that perform extra error checking against bad arguments. Many functions exhibit Undefined Behavior when passed a null pointer, for instance. The Debug libraries will catch quite a few of those, whereas the Release versions assume you pass valid pointers only.
Now DLL's can reference each other; there's a whoel dependency graph. That's why the Dependency Walker tool exists: it figures out which DLL's rqeuire which other DLL's, and this will tell you why you need the *D version.
Thank you very much for all your inputs, I was able to learn a fair bit from this. It turns out the issue was (of course) entirely my fault, as when setting up the Allegro 5 dependencies in the project settings (under General->Linker) I was accidentally including a dependency for the debug version of the Allegro monolith-md.dll as well as the non-debug version in my Release build, and that .dll was in turn referencing the *D version of the MSVCR .dll. The issue has been resolved by removing that dependency from the Release build of my game.
Install dependency walker on that machine. Load the exe. Check if any of the dependent dlls are missing.

How should/could/must I handle the dll that my C++ projects depend on?

I'm lost here and I have no clue how to proceed. This is not a question about how to make my program work, this is a question about how to stop wasting my time.
My programming environment is Visual Studio 2013 on windows, in C++.
I use 3 libraries extensively, namely: boost (using dynamic linking), OpenCV, and Qt.
During the development, I have configured VS to look at those 3 libraries by default for include and .lib. I have also added the 3 folders containing all the dlls to my PATH environment variable.
It works, but it is sometime painful, let me explain you when.
First hassle: Anytime I have a LNK error telling me I miss a function, it is usually on OpenCV since it has only one include file referencing all the functions. I have to look at OpenCV's source code to see what module this function belongs to and to know what I must link my program to.
Second Hassle: When comes the time to deploy my application, I have to ship it with all the relevant dlls. To know which one I need, I open dependency walker and try to forget nothing, I have then to test it on a different computer because 102% of the time I have missed a couple, and then I have to configure my Installer generator to include all those one by one.
Third Hassle: To ease a little bit the process of configuring a new development machine, I have recently switched to NuGet. It is great, I add boost with a couple of clicks to any project. But now my boost DLLs are everywhere, I have one folder per boost library, and since there are dozens of those I can't even add them all at once to my PATH now, so I have to move them manually to the appropriate folder, and that is really not what I want to do with my not-so-precious-but-who-are-you-to-judge time
I have looked around and couldn't find any good practice regarding this issue, maybe because they are too obvious, or too specific to a particular setup.
How do you do? How would you do if you were me?
We put all our external dependencies in version control along with the code. This ensures that all code can build "out of the box" on any of our development machines and also ensures that for any given version of the code, we know exactly which dependencies is has.
The best way to check for missing dependencies is how have a good automated test suite, if you've got comprehensive converge then if your tests pass you must have deployed the required libraries.
In terms of linking to the appropriate libraries, unfortunately, that just sounds like an issue with the structure of OpenCV (I'm not familiar with OpenCV). I tend to use dumpbin under Windows and nm under Linux to easily grep for symbols when I get link errors with an unfamiliar library.

Compile for release

I was writing a simple pong application and while its not finished I'd lie to be able to figure out how to compile it for release. I get no errors and i linked against SDL, SDLmain,SDL_image,SDL_ttf but when people on other computers try to run it (both the debug and release) it closes as if it's missing files. I put SDL.dll,SDL_image.dll, SDL-ttf.dll all in there along with the images i use in the program, it works fine on my computer so that says theres a file I'm missing for it...but what would that be?
EDIT:
Finally after 30 minutes i figured it out: when including SDL_image.dll you also have to include SDL_image.dll's dependencies : zlib1.dll,libjjpeg-x.dll,libpng..etc
A good way to solve this sort of problem (if it's DLL related) is to use Dependency Walker. This will show you all the dependencies of an executable, and the dependencies of the dependencies.
If you run it on the target platform, it will highlight DLLs that are required but not available, making it easier to see why your executable won't run.

How to run C++ program that use PDCurses on other computers?

I've recently started using PDCurses in a C++ game I'm working on. When I compile the program on my own machine (windows) and run the .exe, everything works as it should.
When I take that .exe onto a different computer that doesn't have PDCurses and I try to run it, I get an error about a missing pdcurses.dll file.
After doing a bit of research online, I found out that including the .dll file along with the .exe should make it run but it didn't work for me.
This is how I compiled the program using MinGW: g++ game.cpp -o game -lpdcurses
So my question is, how do I make this program run on computers that don't have PDCurses setup, and also, is there a way to do this by combining the .exe with whatever additional file(s) the system needs to run the program? I've also read that you can do some sort of static linking but so far I've been unable to find a way to do this.
Thanks in advance for the help.
NOTE: In case it matters, I setup PDCurses following this tutorial: http://comptb.cects.com/1848-adding-pdcurses-to-mingw
Not sure if that was the best way to do it but I'm able to compile and run C++ code that uses pdcurses on my computer fine.
Sorry for not posting the exact messages. Here they are:
The first one I got when I didn't include the pdcurses.dll file along with the executable said :
The program can't start because pdcurses.dll is missing from your computer. Try reinstalling the program to fix this problem.
The second one I got after I included the pdcurses.dll:
*The program can't start because libcc_s_dw2-1.dll is missing from your computer. Try reinstalling the program to fix this problem.*
You need to include all the dynamic libraries you linked with. Be careful of licensing, although IIRC there's not much that will bite you with MinGW.
There should be a 'ldd' command if you have the MinGW shell. Try running it on game.exe and it will tell you what libraries you need to run your program. You need to include them all with the exe.
If you want to try and remove the dependency nightmare you can use the static linking (-static) option to your gcc link command. You may not be able to actually do that if you don't have the static versions of your libraries installed. This has other implications - your exe will be bigger and the OS's shared shared page code will not work because it can't tell what parts (DLL code) you are sharing with other apps. In effect, your application will use more memory as a result, although it may be insignificant.
Another option is to get the sources to PDCurses and compile it as a static library. That way you don't have to get involved in the DLL Hell.
Compile it as a C library instead of a C++ library and you should be good to go.