Problem building a ROOT program using shared libraries

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 Then I create routines which makes operations with HParticle objects and I compile them into another shared library, called 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/ -I/afs/ -I. -o run_sTMC_0607 run.C -L/afs/ -lSiguangTMC -L/afs/ -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/ undefined reference to `TParticle::GetPDG(int)' /afs/ undefined reference to `TDatabasePDG::Instance()' /afs/ undefined reference to `TParticle::operator=(TParticle const&)' /afs/ undefined reference to `TParticle::ShowMembers(TMemberInspector&, char*)' /afs/ undefined reference to `TParticle::GetName() const' /afs/ undefined reference to `typeinfo for TParticle' /afs/ undefined reference to `TParticle::Print(char const*) const' /afs/ undefined reference to `non-virtual thunk to TParticle::Sizeof3D() const' /afs/ undefined reference to `TParticle::Sizeof3D() const' /afs/ undefined reference to `TParticle::DistancetoPrimitive(int, int)' /afs/ undefined reference to `TParticle::ExecuteEvent(int, int, int)' /afs/ undefined reference to `TParticle::TParticle()' /afs/ undefined reference to `TParticle::Paint(char const*)' /afs/ undefined reference to `TParticle::GetTitle() const' /afs/ undefined reference to `TDatabasePDG::GetParticle(int) const' /afs/ 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)


-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 done
After this, when I try to load the brand new shared library ‘’ into ROOT, I always get this error:

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


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



My bad, I did another post, link

Cheers, Andre

1 Like