Problem building a ROOT program using shared libraries

Hello!
My problem is the following:
I have made a little program which uses a derivated class from TParticle. I compile this new class into a shared object called libHParticle.so. Then I create routines which makes operations with HParticle objects and I compile them into another shared library, called libSiguangTMC.so. Everything working OK!
Finally, when I want to make use of these libraries to make a program I get the following compilation errors:

g++ -g -O -Wall -fPIC -pthread -I/opt/products/root/5.14.00/include -I/afs/desy.de/user/d/delaossa/sTMC/test/../src/0607 -I/afs/desy.de/user/d/delaossa/sTMC/test/../src/HParticle -I. -o run_sTMC_0607 run.C -L/afs/desy.de/user/d/delaossa/sTMC/test/../src/0607 -lSiguangTMC -L/afs/desy.de/user/d/delaossa/sTMC/test/../src/HParticle -lHParticle -L/opt/products/root/5.14.00/lib -lCore -lCint -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -pthread -lm -ldl -rdynamic /afs/desy.de/user/d/delaossa/sTMC/test/../src/HParticle/libHParticle.so: undefined reference to `TParticle::GetPDG(int)' /afs/desy.de/user/d/delaossa/sTMC/test/../src/HParticle/libHParticle.so: undefined reference to `TDatabasePDG::Instance()' /afs/desy.de/user/d/delaossa/sTMC/test/../src/HParticle/libHParticle.so: undefined reference to `TParticle::operator=(TParticle const&)' /afs/desy.de/user/d/delaossa/sTMC/test/../src/HParticle/libHParticle.so: undefined reference to `TParticle::ShowMembers(TMemberInspector&, char*)' /afs/desy.de/user/d/delaossa/sTMC/test/../src/HParticle/libHParticle.so: undefined reference to `TParticle::GetName() const' /afs/desy.de/user/d/delaossa/sTMC/test/../src/HParticle/libHParticle.so: undefined reference to `typeinfo for TParticle' /afs/desy.de/user/d/delaossa/sTMC/test/../src/HParticle/libHParticle.so: undefined reference to `TParticle::Print(char const*) const' /afs/desy.de/user/d/delaossa/sTMC/test/../src/HParticle/libHParticle.so: undefined reference to `non-virtual thunk to TParticle::Sizeof3D() const' /afs/desy.de/user/d/delaossa/sTMC/test/../src/HParticle/libHParticle.so: undefined reference to `TParticle::Sizeof3D() const' /afs/desy.de/user/d/delaossa/sTMC/test/../src/HParticle/libHParticle.so: undefined reference to `TParticle::DistancetoPrimitive(int, int)' /afs/desy.de/user/d/delaossa/sTMC/test/../src/HParticle/libHParticle.so: undefined reference to `TParticle::ExecuteEvent(int, int, int)' /afs/desy.de/user/d/delaossa/sTMC/test/../src/HParticle/libHParticle.so: undefined reference to `TParticle::TParticle()' /afs/desy.de/user/d/delaossa/sTMC/test/../src/HParticle/libHParticle.so: undefined reference to `TParticle::Paint(char const*)' /afs/desy.de/user/d/delaossa/sTMC/test/../src/HParticle/libHParticle.so: undefined reference to `TParticle::GetTitle() const' /afs/desy.de/user/d/delaossa/sTMC/test/../src/HParticle/libHParticle.so: undefined reference to `TDatabasePDG::GetParticle(int) const' /afs/desy.de/user/d/delaossa/sTMC/test/../src/HParticle/libHParticle.so: undefined reference to `TParticle::~TParticle()' collect2: ld returned 1 exit status
I have attached the program (sTMC.tgz). Just unpack, go inside sTMC dir and type make to compile. The libraries are built ok, but the running program in sTMC/test fails.
Now, the funny thing. I get this error using both ROOT 5.18 and 5.14. But if a change the ROOTLIBS variable defined in sTMC/test/Makefile in the usual way

ROOTLIBS := $(shell root-config --libs)
by this line

ROOTLIBS = -L/${ROOTSYS}/lib -lCint -lCore -lGpad -lGraf3d -lGraf -lGui -lHist -lMatrix -lPhysics -lTree -lEG -lRint -lTreeViewer -lm -ldl

It works using ROOT 5.14, but still crashing with 5.18. :open_mouth: . Anyone can help, please?

Thank you.

oops… I forgot the program: sTMC.tar.gz
Here it is
sTMC.tar.gz (934 KB)

Hi,

-lEG is not part of what root-config --libs gives, so YOu’ll have to add it by hand: root-config --libs -lEG

Cheers, Axel.

Hi Axel,
Thank you very much! It was easy! I got confused with so many libraries in different Makefile versions of the program.
Please accept my apologies for the delay in response. I had problems with my account in ‘Root Talk’.

Now I have another question about shared libraries:
HParticle (which is attached here) is just a program redefining ‘TParticle’ ROOT classes. There, a dictionary and a shared library is built for the new class. Typing ‘make’:

[Kraken]:/HParticle>make g++ -c -g -O -Wall -fPIC -pthread -m32 -I/cern/root/include -I. HParticle.cxx Generating dictionary HParticleDict.cxx... g++ -c -g -O -Wall -fPIC -pthread -m32 -I/cern/root/include -I. HParticleDict.cxx g++ -shared HParticle.o HParticleDict.o -o libHParticle.so libHParticle.so done
After this, when I try to load the brand new shared library ‘libHParticle.so’ into ROOT, I always get this error:

[Kraken]:/HParticle>root -l root [0] gSystem->Load("libHParticle.so"); dlopen error: /home/delaossa/hermes/sTMC/src/HParticle/./libHParticle.so: undefined symbol: _ZN9TParticle19DistancetoPrimitiveEii Load Error: Failed to load Dynamic link library /home/delaossa/hermes/sTMC/src/HParticle/./libHParticle.so
Why?
HParticle.tar.gz (38.9 KB)

Hi,

The issue is that ROOT does not know to load libEG,so when loading your library. You have 3 choices:
[ul]1. Load the library by hand: gSystem->Load("libEG");
2. Link you library against libEG
3. write a rootmap file
[/ul]

Cheers,
Philippe.

Thanks!

My bad, I did another post, link

Cheers, Andre

1 Like