Use private C++ runtime library on linux

In Windows, the dynamic loader always looks for modules in the path of the loaded executable first, making it possible to have private libraries without affecting system libraries.

The dynamic loader on Linux only looks for libraries in a fixed path, in the sense that it is independent on the chosen binary. I needed GCC 5 for its overflow checked arithmetic functions, but since the C++ ABI changed between 4.9 and 5, some applications became unstable and recompiling them solved the issue. While waiting for my distro [kubuntu] to upgrade the default compiler, is it possible to have newly compiled application linking to the new runtime, while packaged application still links to the old library, either by static linkage, or something that mimics the Windows behavior?

One way of emulating it would be to create a wrapper script

LD_LIBRARY_PATH=$(dirname $(which your_file)) your_file

And after the linking step copy the affected library but it is sort of a hack.

Source: gcc

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.