3

Before I started developing any more c++ projects, I wanted to establish a good multiplatform environment and use some basic form of revisioning (rsync). To do this I learn't how to construct makefiles (with uname variables) and also started using mingw inside of a cygwin environment on windows. This was so that I could hopefully develop on all platforms in a homogeneous manner under a unix like shell.

What I don't understand is the standard working practice for distributing compiled programs that have dependencies on dynamic libraries. For example when I compile with mingw on windows, I need to add the most basic of libraries (libstdc++-6.dll) to the executable directory for it to run. Just for the standard library I need to add three .dll's and even then dependency walker shows countless more although it appears to run.

Surely every library needs to be included as it would be impossible to guarantee the end user would have it locally?

If this is the case, is it common to just include the dynamic libraries within the same directory as the executable?

I also read that .so files act as an import library as well as a dynamic library. Would these then also need to be included in the executable directory?

Cmake is useful for such things and I presume I'll end up using it. This said I thought it would be helpful for me to learn how to accomplish cross platform development without it first.

pjs
  • 18,696
  • 4
  • 27
  • 56
josh247
  • 155
  • 1
  • 13
  • Better use `git` than `rsync` for version control. And consider making a package (e.g. a `*.deb`) for your software, at least for Linux. – Basile Starynkevitch Jul 06 '14 at 15:24
  • This is true, I would like to learn how to use git and Linux/Mac do appear to be easier to manage than windows. What I would like to know for example is do you include the standard library in your distributed package? – josh247 Jul 06 '14 at 15:30

2 Answers2

1

No, you do not need to include every .dll mentioned in dependency walker. Most of them, including the standard library, are guaranteed by Microsoft/Posix/etc. to be available with the OS.

A good rule of thumb is that if you had to install it on your computer, you probably have to install it on the users computer.

Baruch
  • 20,590
  • 28
  • 126
  • 201
  • One of my issues is that i'm using mingw from within cygwin which means my standard system libraries must be named differently in that environment, as they aren't found when I try running from windows explorer. – josh247 Jul 09 '14 at 12:20
  • Cygwin, and to a lesser extent mingw, links against it's own versions of many libraries. That is how it allows compiling and running programs that make all kinds of POSIX library and system calls to run on windows. I think, however, that the whole thing is contained in one or two `.dll` files that you would have to redistribute, and in the case of mingw there is a compiler option (don't remember exactly which) to statically link this in so no additional library need be distributed. – Baruch Jul 09 '14 at 12:41
  • I found the static option (-static-lib) and so that will work for now. Planning on changing over to cmake/git maybe when the project gets a little bigger. – josh247 Jul 09 '14 at 17:22
0

Two things:

  1. You can include partial libraries if your dependencies aren't very large in a subdirectory called lib and compile them there for compiling your application. It's fairly common in C++ to include a partial distribution of Boost in a lib folder if you depend on say, boost filesystem or boost thread or what have you.

  2. Tools such as CMake are phenomenal for easily constructing cross platform makefiles. They take care of all the work of finding libraries if they are installed and can even be written to download missing libraries. A solution such as this would keep your distribution code small and still get you everything you need. Personally I use CMake for all my applications because I hate writing makefiles and glob_recurse is so useful.

  • So is there a way to have all your included dynamic libraries in a subdirectory of the executable for distribution? Also are there any good learning resources for CMake you would recommend? – josh247 Jul 09 '14 at 12:24
  • @josh247 The best way to learn CMake is probably to read a bunch of small example files and try to understand what each line actually does. The simplest CMake files can be only a few lines long and quite clear. You can include libraries in source and compile them, I don't think that having a precompiled library is feasible unless you already know your exact target system. – Thomas of the Scotts Jul 09 '14 at 17:43