C++ – Linking Statically with glibc and libstdc++

cgcclinux

I'm writing a cross-platform application which is not GNU GPL compatible. The major problem I'm currently facing is that the application is linked dynamically with glibc and libstdc++, and almost every new major update to the libraries are not backwards compatible. Hence, random crashes are seen in my application.

As a workaround, I distribute binaries of my application compiled on several different systems (with different C/C++ runtime versions). But I want to do without this. So my question is, keeping licensing and everything in mind, can I link against glibc and libstdc++ statically? Also, will this cause issues with rtld?

Best Answer

You don't need to.

Copy the original libraries you linked against to a directory (../lib in this example) in your application folder.

Like:

my_app_install_path

  1. .bin
  2. lib
  3. documentation

Rename you app for something like app.bin. Substitute your app for a little shell script that sets the enviroment variable LD_LIBRARY_PATH to the library path (and concatenate the previous LD_LIBRARY_PATH contents, if any). Now ld should be able to find the dynamic libraries you linked against and you don't need to compile them statically to your executable.

Remember to comply with the LGPL adding the given attribution to the libraries and pointing in the documentation where the source can be downloaded.