Is it possible to use external static libraries in ROOT?
In particular, I was trying to use absl::StrCat from the abseil-cpp library in ROOT (interactively). Abseil comes with a CMakeLists.txt that produce libabsl_strings.a. Can I somehow load this into ROOT?
I managed to do it by adding set(CMAKE_POSITION_INDEPENDENT_CODE ON)
to the CMakeLists.txt, recompiling, running
ar -x libabsl_strings.a
g++ -std=c++11 -shared *.o -o libabsl_strings.so
But this is probably not how it should be done… It seemed rather complicated and unpacking + repacking .a to .so feels wrong. Can’t one use the .a file directly? Do I need PIC? When I compile programs normally, I can simply link the .a file.
How do I do this “right”? I’m not an expert with all the build tools.
But it doesn’t work interactively on command line before running the .x or .L command (with +). Hm… is it a good idea to put something like gROOT->ProcessLine(".L lib_loader.C+"); in the rootlogon.C file?
That’s what I was doing myself (first “AddLinkedLibs” and then loading an almost “dummy.cxx++” script which used anything from my library, so that the linker was “forced” to take it, but you may also need to play with “-Wl,-whole-archive” or its equivalent on OSX).
But I think a better solution is to re-link your archive library into a shared one (like you do it in your first post above). I guess you could try to simplify this step: g++ -std=c++11 -shared -o libabsl_strings.so -Wl,-whole-archive libabsl_strings.a
I tried the “-Wl,-whole-archive” in my CMakeLists yesterday (I wanted to produce the .so file from there) but somehow failed with some linker errors (maybe I should try from command line fist to find out if it is a cmake issue or a “real” problem). Thanks a lot for your suggestion with the AddLinkedLibs. It works for now. I will try with that switch again as soon as I find some time for it.