0

I have coded an app in c++ using the SFML library. I configured it into code blocks to run the program. Let's say I now want to send this app to my friend, what's the best way I can do this so that he doesn't have to go through downloading a lot of stuff to run it?

I am using the MinGW compiler.

  • This shows you how to create a .exe file in code blocks. https://stackoverflow.com/questions/8450121/how-do-i-create-a-exe-from-a-cpp-file-in-code-blocks – Nick Juelich Sep 03 '20 at 18:43
  • Do you want to send your friend just the executable App, or do you want them to be able to compile the code themselves? – πάντα ῥεῖ Sep 03 '20 at 18:46
  • I use NSIS to make an installer. [https://nsis.sourceforge.io/Download](https://nsis.sourceforge.io/Download) – drescherjm Sep 03 '20 at 18:48
  • @πάνταῥεῖ I uploaded the whole project with the exe on Github and he downloaded it, it has the additional sfml .dll ones but when he runs the exe he gets an error, saying something not found, which was immediately resolved after he installed the gcc compiler –  Sep 03 '20 at 19:07
  • @NickJuelich making an exe file isn't tough, it's already there in a folder when you build it, but he wasn't able to run it –  Sep 03 '20 at 19:10
  • @AryanParekh "making an exe file isn't tough, it's already there in a folder when you build it, but he wasn't able to run it" - Your .exe is not a standalone thing. It has *dependencies* on other files (libraries) and you need to ship those libraries along with your executable or it cannot run. – Jesper Juhl Sep 03 '20 at 19:15
  • @JesperJuhl Okay this answers my question, I will try it at once. –  Sep 03 '20 at 19:21
  • Did you try to compile with `static` option to get a.exe with less dependencies? – Damien Sep 03 '20 at 19:46
  • 1
    ***which was immediately resolved after he installed the gcc compiler*** Probably means that he did not have the proper mingw runtime dlls in any folder of the `PATH` environment variable. On a typical windows machine this will be expected. – drescherjm Sep 03 '20 at 19:52
  • 1
    In an installer package you could package the mingw dlls (compiler is not needed) + your application + sfml dlls .. – drescherjm Sep 03 '20 at 19:57
  • Although somwhat old this may help: [https://stackoverflow.com/questions/31449769/distribute-a-program-compiled-with-mingw-g](https://stackoverflow.com/questions/31449769/distribute-a-program-compiled-with-mingw-g) – drescherjm Sep 03 '20 at 20:29
  • @Damien I'm not sure what that means –  Sep 03 '20 at 20:58
  • You can build static sfml and also enable static runtimes for mingw, – drescherjm Sep 03 '20 at 21:22
  • Related to static: [https://stackoverflow.com/questions/13768515/how-to-do-static-linking-of-libwinpthread-1-dll-in-mingw](https://stackoverflow.com/questions/13768515/how-to-do-static-linking-of-libwinpthread-1-dll-in-mingw) – drescherjm Sep 03 '20 at 21:25

3 Answers3

1

Create an installer or package. For example; On RedHat Linux you'd want to create a RPM package. On Windows you want to create a MSI file. Whatever you do, the package you create should bundle up everything your application needs to run and put it into the correct location(s) on the target system. This includes your executable but also any libraries you use (including your compilers runtime libraries).

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70
  • Does this mean I need to include the mingw compiler in the package? –  Sep 03 '20 at 19:08
  • 1
    "Does this mean I need to include the mingw compiler in the package?" - No. You don't need to include the compiler. But you *do* need to include the compilers *runtime libraries* (goes for *any* compiler) and, of course, also the SFML library you use, as well as any other library you may be using. – Jesper Juhl Sep 03 '20 at 19:11
  • runtime libraries mean anything that I use in my program, for example `iostream` –  Sep 03 '20 at 19:14
  • 1
    @AryanParekh stuff from `iosteam` will be implemented by your compilers runtime libraries, yes. So you need to include them. – Jesper Juhl Sep 03 '20 at 19:17
1

In most cases just shipping your .exe and all of its dependancies is enough. In some cases you may also need to ship other files needed to run the application like configuration files, images, icons...

You can use copypedeps with the -r flag from https://github.com/brechtsanders/pedeps to copy your .exe along with its dependancy .dll files into an empty folder.

Then you can just zip everything in that folder and send it to somebody who can just unzip it an run the .exe.

Or you can make a proper installer to distribute the same files.

Brecht Sanders
  • 6,215
  • 1
  • 16
  • 40
1

Your program needs some .dlls to run: some are the system ones, some are shipped with the compiler, and some come from the libraries you use (SFML). You need to ship all those .dlls (except the system ones) with your .exe, and they should be in the same directory.

It doesn't really matter if you make a proper installer or send your friend a zip archive. (If it's an archive, they might have to manually extract it before running the .exe.)

The question is how to figure out which .dlls to ship. There are several approaches:

  • Open the console, cd to where your .exe is, do set PATH= and try running the executable by typing its name. Since the compiler installation is no longer in the PATH, it shouldn't see the .dlls in there, and it should complain about them being missing. After you provide one .dll, it will ask for the next one.

  • A more civilized approach is to use a tool like ntdll to list all .dlls your app uses. Then copy them, ignoring the system ones (located in C:\Windows or subdirectories).

Note that both approaches rely on there being no extraneous .dlls in C:\Windows or subdirectories; some poorly written installers like to put their own .dlls in there. To check for that, make a list of all .dlls that come with your compiler (they should be in the same directory as the gcc.exe), and the ones that come from your libraries (SFML). Then look for the .dlls with the same name in C:\Windows and subdirectories, and if you find any, remove them.

HolyBlackCat
  • 78,603
  • 9
  • 131
  • 207