Cling: How to work with two versions of


I need to be able to work with 2 versions of simultaneously. In a command line I could do (i.e. compile a program with gcc-4.9.3 and link against a library which requires a newer version of than the one supplied with gcc-4.9.3):

$ g++ -v
gcc version 4.9.3 (GCC)
$ g++ ... -L$HOME/bin/gcc-5.4.0/lib64 \
          -Wl,-rpath=$HOME/bin/gcc-5.4.0/lib64 \
          -L/path/to/library/compiled/with/gcc5 -lXXX \
          -Wl,-rpath=/path/to/library/compiled/with/gcc5 \
          -o program program.C
$ ./program
# nice result

and it works. But in Cling I try to do:

const TString libDir = "/path/to/library/compiled/with/gcc5";
const TString gcc5LibDir = "$HOME/bin/gcc-5.4.0/lib64";
gSystem->AddLinkedLibs(Form("%1$s/ -Wl,-rpath=%1$s", libDir.Data()));
gSystem->AddLinkedLibs(Form("%1$s/ -Wl,-rpath=%1$s", gcc5LibDir.Data()));
.x program.C+

and it gives me

cling::DynamicLibraryManager::loadLibrary(): $HOME/bin/gcc-4.9.3/lib64/ version `CXXABI_1.3.9’ not found (required by /path/to/library/compiled/with/gcc5/

If I start ROOT like so:

env LD_LIBRARY_PATH=$HOME/bin/gcc-5.4.0/lib64:$LD_LIBRARY_PATH root.exe -b -l

then the above problem does not appear.

Question: could you please let me know what I could do right inside a ROOT session to be able to run .x program.C+ afterwards? I.e. I do not want to start ROOT in an unusual way and instead want to put any required commands into my macro. Somehow, I need to tell Cling where to search for a with `CXXABI_1.3.9’.

The following ideas did not work for me:

* gSystem->Load(Form("%s/", gcc5LibDir.Data())); // load error = 1
* const Char_t * const evLDLP = gSystem->Getenv("LD_LIBRARY_PATH");
  gSystem->Setenv("LD_LIBRARY_PATH", Form("%s:%s", gcc5LibDir.Data(), evLDLP));

What is interesting is that the needed library is loaded but Cling still does not see it:

$HOME/bin/gcc-4.9.3/lib64/ version `CXXABI_1.3.9' not 
found (required by /path/to/library/compiled/with/gcc5/
root [2] gSystem->ListLibraries()

Loaded shared libraries

Changing PATH or LD_LIBRARY_PATH in ~/.bashrc is not an option - the used compiler has to stay the same.

Thank you very much for your help!


What we support is building ROOT with a different gcc: we will use the same gcc that ROOT was built with at runtime. So please build ROOT with the non-default gcc and it should work. This approach is used on a daily basis, in production, for instance on SLC6; it’s well tested.

Cheers, Axel

Hi Axel,

This is not an option in general. Imagine, that one has 2 libraries, both of which were built with different versions of GCC, and does not have source code for neither of them. It is not possible then to rebuild ROOT such that the GCC version would match both libraries.

It should be possible to do in ROOT what I did when I compiled explicitly with g++ using “-Wl,-rpath” options in my original post.

Plus, there is no need to use a different compiler: as you can see even if I use the same compiler, that was used to compile ROOT, I can still use the library compiled with a different version of GCC. It is Cling (not the compiler) that I have a problem with, since Cling can not find the needed library (while GCC can).



We do not recommend to dynamically link binaries / libraries built with different GCC versions. And we are doing that out of experience; there have been ABI changes in between, and making sure that cling sees the correct headers is non-trivial.

I.e. fine, I agree that this is a missing feature. But you are the first person to request this in 20 years of ROOT (as far as I know / remember), and I am not sure it’s a feature that is “sustainable”: it adds a whole dimension of configuration complexity that we will have a hard time to support, test and maintain - and diagnose in case of problem reports.

Cheers, Axel.

Hi Alex,

I agree with you: it is better to not mix libraries built with different versions of GCC, but sometimes one just does not have a choice (i.e. when source could is not available and it is not possible to rebuild a library).

I guess, I will need to either build explicitly with GCC or find some hacky ways to work around the limitations. Cling just makes it quite easy to add external libraries in a modular way - it makes importing of libraries similar to Python (not as easy, but close), which is why I would certainly prefer to do it through Cling.

Thank you very much for your feedback.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.