3

I'm developing a c++ program on Ubuntu 16.04 using cmake, compiling with g++5 and clang++-3.8.

Now I'd like to make this Program availabile for 14.04, too, but as I'm using a lot of c++14 features I can't just recompile it on that system. Instead, I wanted to ask if/how it is possible to package all dependencies (in particular the c++ standard library) in a way that I can just unpack a folder on the target system and run the app.

Ideally I'm looking for some automated/scripted solution that I can add to my cmake build.

Bonus Question:
For now, this is just a simple command line program for which I can easily recompile all 3rd party dependencies (and in fact I do). In the long run however, I'd also like to port a QT application. Ideally the solution would also work for that scenario.

MikeMB
  • 20,029
  • 9
  • 57
  • 102
  • google://docker – arrowd Jul 26 '17 at 08:16
  • @arrowd: can you elaborate please? I can't install docker on the target system and I can't compile my program on Ubuntu 14.04. – MikeMB Jul 26 '17 at 08:20
  • You can distribute your program as docker-packed container. – arrowd Jul 26 '17 at 08:22
  • 1
    If you're worried about the standard library, you can statically link it. https://stackoverflow.com/questions/26103966/how-can-i-statically-link-standard-library-to-my-c-program – xaxxon Jul 26 '17 at 08:30
  • @xaxxon: Well, it is a bit more than just the standard library. I'm also using some other libraries, but the standard library is the only one I know for sure that the version on ubuntu14.04 is too old. However, as all libraries link against the stl, I probably also have to package them. Linking everything statically should probably work for my current scenario, but afaik it wont work - becomes pretty complicated when e.g. linking qt or other more complex system libraries. – MikeMB Jul 26 '17 at 08:48

1 Answers1

1

The worst part of your contitions is an incompatible standard library. You have to link it statically anyway (see comments to your answer).

A number of options:

Completely static linking:

I think it's easiest way for you, but it requires that you can build (or get by any way) all third-party libs as static. If you can't for some reason it's not your option.

You just build your app as usual and then link it with all libs you need statically (see documentation for your compiler). Thus you get completely dependencies-free executable, it will work on any ABI-compatible system (you may need to check if x86 executable works on x86_64).

Partially static linking

You link statically everything you can and dynamically other. So you distribute all dynamic libs (*.so) along with you app (in path/to/app/lib or path/to/app/ folder), so you don't depend on system libraries. Create your deb package which brings all files into /opt or $HOME/appname folder. You have to load all dynamic libs either "by hand" or ask compiler to do it on linking stage (see documentation).

Docker container

I don't know much about it but I know exactly it requires that docker be installed on target system (not your option).

Useful links:

g++ link options

static linking manual

Finding Dynamic or Shared Libraries

There are similar docs for clang, google it.