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

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.

Related

How to create a portable executable with allegro 4.4.2

So I am creating a C++ program using the allegro version 4.4.2 library and I need to be able to produce an executable package which I can submit to a course instructor and have run on his computer without issues. I am developing the program using DevC++. If I am understanding this correctly so far, I need to link to a static library for allegro and then the executable should include the library info and thus the library itself is not necessary to have included in the executable package. I have also seen some recommendations regarding third party tools that produce executable packages, but these seem to be more general (not necessarily allegro compatible?) and I am hoping to avoid downloading more third party software.
I have tried linking to the static library liballegro-4.4.2-monolith-static-mt.a but for some reason when I do this I get a whole slew of undefined reference compile time errors. I have read that it is necessary to have #define ALLEGRO_STATICLINK included in the project, I have this statement at the top of my main source file but I am not sure if I am meant to define this somewhere in the project options instead?
Any guidance or link to resources which will help me solve my problem would be extremely appreciated! I am just getting into the meat of programming with C++ beginning to learn object oriented programming methods, I still occasionally struggle with the basics so thank you in advance for your help!
Backstory (if interested/relevant?): I am taking a Game AI programming course for which we need to create some example programs to demonstrate AI algorithms. The course specifies Java but I am most familiar with C++ and the course instructor says this is fine but I must be able to submit an executable to him which he can just run on his computer without issues. To best achieve what the course asks I feel the allegro library (which I already have installed) will be of great help, mostly for drawing graphics to the screen and such.
So I just ended up using a dynamically linked version of my program and including the appropriate .dll files which turned out to be a lot less work than I thought it would be.
Basically I just had to ensure the allegro-4.4.2-md.dll from the bin folder was included in the folder with the executable. I then sent off the package (the .exe compiled file and the needed supporting files such as bitmaps sound files etc) to a few friends and had them try to run it. They then gave me the warnings from their computers along the lines of "Test.exe cannot be run ****.dll cannot be found".
I searched the exact names of the dll files they were receiving warnings for in the folder with my game and voila it now seems to execute on whatever PC it is sent to.

Program works in CLion IDE, but exe doesn't work

I started programming in C++ using CLion IDE.
When I run the program inside the IDE it works. However, opening the .exe file outside the IDE generates a bunch of errors:
The code execution cannot proceed because libgcc_s_seh-1.dll was not found. Reinstalling the program may fix this problem.
Hitting OK pops the same message again with a different dll.
Why does this happen? What are the different ways to fix it? What is the best option?
You always need to ship any libraries your application is linked with along with your application. The libraries are just as much a part of your app as the code you wrote yourself. This includes your compilers runtime libraries (which you forgot in this case).

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.

C++: How do you run an executable in windows that uses libcurl?

I wrote a utility to grab information off the web using libcurl and written and compiled using Cygwin on a Windows 7 machine. I'd like to be able to run the executable in the windows environment, but when I do I get the error "The program can't start because cygcurl-4.dll is missing from your computer." I'm not sure how to resolve this, because even if I install libcurl for windows it seems like it's looking specifically for the Cygwin version. Ideally I'd like to figure out how to make the program self contained so it can function without people having to install any libraries themselves.
"The program can't start because cygcurl-4.dll is missing from your computer."
You only need to distribute cygcurl-4.dll with your executable to solve this (put the dll into the same folder).
It should be located in the binaries folder of Cygwin.
In order to make your program self-contained, you should try to compile libcurl on Windows as a static library (a .lib file) without cygwin. Some people say that it is doable. If you're unlucky, maybe you should try some other similar library.

Porting from Linux to Windows, tm.sys

I apologize if this question is vague, but I can't really get any more specific. I have a pretty large project that I'm porting to Windows. After finally getting it to compile with cl, and link with link.exe, I run it and get the following 'System Error':
The program can't start because C:\Windows\SYSTEM32\tm.sys is missing
from your computer. Try reinstalling the program to fix this problem.
It's a console application which requires no installation. Does tm.sys signify anything to you, perhaps a Linux dependency that I missed that Windows allowed during compile time but is now interpreting oddly? I'm looking for hints/guesses/anything to run with because I fully realize that my description (and lack of code example) is less than satisfying.
It is a C project with some mixed in C++ code (C++ accounts for maybe 1%), and is built using the WDK. The compilation yields 5 static .lib files and one .exe file.
The issue resided within ntoskrnl.lib. I removed that unnecessary library from my sources file and the executable ran fine. I'm not sure the significance of tm.sys, but lesson learned: KNOW YOUR DEPENDENCIES!