# Linking problem to libTree.so

**URL:** <https://root-forum.cern.ch/t/linking-problem-to-libtree-so/13697>\
**Category:** ROOT\
**Created:** [January 30, 2012, 6:23pm UTC](https://root-forum.cern.ch/t/linking-problem-to-libtree-so/13697 "2012-01-30T18:23:25Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![ajafari](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@ajafari](https://root-forum.cern.ch/u/ajafari)\
**Post date:** [January 30, 2012, 6:23pm UTC](https://root-forum.cern.ch/t/linking-problem-to-libtree-so/13697/1 "2012-01-30T18:23:25Z")

</div>

Hi all,  
I am trying to compile a code which uses the TTree class. Hence, I execut (\*) to compile and link my executable to needed libraries. But the compiler does not realize that I need “-lTree” to be linked to my .o.  
I think so because after compiling successfully, I get this (\*\*) runtime error. Besides, the “ldd” command output does not contain libTree.  
I cured it by adding gSystem-\>Load(“[libTree.so](http://libTree.so)”) in my .C file, but it is not a wise and permanent solustion.

Can somebody help me understand what is wrong with my linking?

Thanks a lot,  
Nadjieh

(\*)  
ROOTGLIBS =$(shell root-config --glibs) -lMinuit  
ROOTCFLAGS =$(shell root-config --cflags)  
LIBS = userLibs  
HEADERS = userheaders

```
@echo "Compiling the SelectAndSave .... \n"
$(CXX) SelectAndSave.C -c -o SelectAndSave.o -O0 $(ROOTCFLAGS) -fPIC $(HEADERS)
@echo "Linking ...... \n"
g++ SelectAndSave.o -o SelectAndSave $(ROOTGLIBS) -lEG $(LIBS) -v -g -fPIC -O0 -I/opt/root/include -m64 -pthread $(HEADERS)

```

(\*\*)  
Warning in TClass::TClass: no dictionary for class TTree is available  
Warning in TClass::TClass: no dictionary for class TBranchElement is available  
Warning in TClass::TClass: no dictionary for class TBranch is available  
Warning in TClass::TClass: no dictionary for class TLeafElement is available  
Warning in TClass::TClass: no dictionary for class TLeaf is available  
Warning in TClass::TClass: no dictionary for class TVirtualIndex is available  
Warning in TClass::TClass: no dictionary for class TBranchRef is available  
Error in TBufferFile::ReadClassBuffer: class: TNamed, attempting to access a wrong version: 18, object skipped at offset 63  
Error in TBufferFile::CheckByteCount: object of class TNamed read too few bytes: 2 instead of 10314  
Error in TBufferFile::ReadClassBuffer: class: TNamed, attempting to access a wrong version: 18, object skipped at offset 60  
Error in TBufferFile::CheckByteCount: object of class TNamed read too few bytes: 2 instead of 493722  
runTree:  
Error in TFile::Read: Key not found

\*\*\* Break \*\*\* segmentation violation

# =========================================================== There was a crash. This is the entire stack trace of all threads:

# #0 0x00007f25d3cc811e in waitpid () from /lib/x86\_64-linux-gnu/libc.so.6 #1 0x00007f25d3c5ee0e in ?? () from /lib/x86\_64-linux-gnu/libc.so.6 #2 0x00007f25d5c0ae37 in TUnixSystem::StackTrace() () from /opt/root/lib/libCore.so #3 0x00007f25d5c0d703 in TUnixSystem::DispatchSignals(ESignals) () from /opt/root/lib/libCore.so #4 #5 0x000000000043c6f5 in PracticalEvent::PracticalEvent(TTree\*, TTree\*, bool, bool, bool, bool, bool, bool, bool, bool) () #6 0x0000000000429fa9 in main ()

# The lines below might hint at the cause of the crash. If they do not help you then please submit a bug report at [root.cern.ch/bugs](http://root.cern.ch/bugs). Please post the ENTIRE stack trace from above as an attachment in addition to anything else that might help us fixing this issue.

# #5 0x000000000043c6f5 in PracticalEvent::PracticalEvent(TTree\*, TTree\*, bool, bool, bool, bool, bool, bool, bool, bool) () #6 0x0000000000429fa9 in main ()

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [January 31, 2012, 9:46pm UTC](https://root-forum.cern.ch/t/linking-problem-to-libtree-so/13697/2 "2012-01-31T21:46:03Z")

</div>

[quote] think so because after compiling successfully, I get this (\*\*) runtime error. Besides, the “ldd” command output does not contain libTree. [/quote]Yes, this would indeed be fatal … Which version of ROOT are you using? What is the value of `root-config --glibs`? What is your OS?

Philippe.

---

<div class="post-metadata">

**Author:** ![ajafari](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@ajafari](https://root-forum.cern.ch/u/ajafari)\
**Post date:** [February 1, 2012, 10:28am UTC](https://root-forum.cern.ch/t/linking-problem-to-libtree-so/13697/3 "2012-02-01T10:28:00Z")

</div>

Hi,  
My root version is 5.32.00 and I am using ubuntu 11.4 OS.  
The outcome of `root-config --glibs` is:  
-L/opt/root/lib -lGui -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic

It contains lTree …

Thanks,  
Nadjieh

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [February 1, 2012, 1:38pm UTC](https://root-forum.cern.ch/t/linking-problem-to-libtree-so/13697/4 "2012-02-01T13:38:43Z")

</div>

Hi Nadjieh,

Ubuntu’s linker by default strips for the linking any libraries that does not have any use in the source being compiled.

What is the content of your main.cxx? (I suspect that there is neither a direct connection to TTree nor is the ROOT environment setup enough to enable the autoloading of (ROOT) libraries.

Cheers,  
Philippe.

---

<div class="post-metadata">

**Author:** ![ajafari](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@ajafari](https://root-forum.cern.ch/u/ajafari)\
**Post date:** [February 4, 2012, 7:54am UTC](https://root-forum.cern.ch/t/linking-problem-to-libtree-so/13697/5 "2012-02-04T07:54:29Z")

</div>

Hi Philippe,

[quote=“pcanal”]

What is the content of your main.cxx? (I suspect that there is neither a direct connection to TTree nor is the ROOT environment setup enough to enable the autoloading of (ROOT) libraries.

Philippe.[/quote]

Actually it does. I use TTree to read my nTuples and this is where the code crashes at runtime.  
This is exactly the strange part. I have

gSystem-\>Load(“[libTree.so](http://libTree.so)”);  
TTree\* runTree = (TTree\*) f-\>Get(“runTree”);

in my .C file. The code crashes at second line if I comment the first line:

Warning in TClass::TClass: no dictionary for class TTree is available  
Warning in TClass::TClass: no dictionary for class TBranchElement is available  
Warning in TClass::TClass: no dictionary for class TBranch is available  
Warning in TClass::TClass: no dictionary for class TLeafElement is available  
Warning in TClass::TClass: no dictionary for class TLeaf is available  
Warning in TClass::TClass: no dictionary for class TVirtualIndex is available  
Warning in TClass::TClass: no dictionary for class TBranchRef is available  
Error in TBufferFile::ReadClassBuffer: class: TNamed, attempting to access a wrong version: 18, object skipped at offset 63  
Error in TBufferFile::CheckByteCount: object of class TNamed read too few bytes: 2 instead of 10314  
Error in TBufferFile::ReadClassBuffer: class: TNamed, attempting to access a wrong version: 18, object skipped at offset 60  
Error in TBufferFile::CheckByteCount: object of class TNamed read too few bytes: 2 instead of 493722  
runTree:  
Error in TFile::Read: Key not found

I am rather confused with this.

Cheers,  
Nadjieh

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [February 4, 2012, 3:01pm UTC](https://root-forum.cern.ch/t/linking-problem-to-libtree-so/13697/6 "2012-02-04T15:01:52Z")

</div>

Hi Nadjieh,

Your ROOT build and/or your ROOT installation is corrupted is some ways (i.e. one possibility is that an older version is still on the PATH or LD\_LIBRARY\_PATH).

`gSystem->Load("libTree.so");
TTree* runTree = (TTree*) f->Get("runTree");`The 1st line should never be necessary and even in the case where libTree is either not linked against or automatically load, it should not be leading to a crash …

Can you check that your $PATH variable and $LD\_LIBRARY\_PATH and $ROOTSYS variable points to a single installation of ROOT and that the location of the ROOT library files (usually $ROOTSYS/lib) contains both .so and .rootmap files?

Cheers,  
Philippe.

---

<div class="post-metadata">

**Author:** ![ajafari](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@ajafari](https://root-forum.cern.ch/u/ajafari)\
**Post date:** [February 4, 2012, 5:08pm UTC](https://root-forum.cern.ch/t/linking-problem-to-libtree-so/13697/7 "2012-02-04T17:08:00Z")

</div>

Hello Philippe,

> [@pcanal](#):
>
> Can you check that your $PATH variable and $LD\_LIBRARY\_PATH and $ROOTSYS variable points to a single installation of ROOT and that the location of the ROOT library files (usually $ROOTSYS/lib) contains both .so and .rootmap files?

I have installed the current version (5.32) in /opt/root/ directory. The output for PATH and other variabes you suggested are:  
$PATH = /opt/root/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

$ROOTSYS = /opt/root

$LD\_LIBRARY\_PATH = /opt/root/lib:/home/nadjieh/lib

So I think all paths are consistently pointing to the same directory. I also checked the existence of .rootmap files:  
$ l /opt/root/lib/libTree\*  
/opt/root/lib/libTreePlayer.rootmap /opt/root/lib/libTree.rootmap /opt/root/lib/libTreeViewer.rootmap  
/opt/root/lib/libTreePlayer.so\* /opt/root/lib/libTree.so\* /opt/root/lib/libTreeViewer.so\*

which is fine.  
Do you think that cleaning the current installation and reinstalling can help? If so, which kind of cleaning command works really cleaner and erase all root-connected things?

Cheers,  
Nadjieh

---

<div class="post-metadata">

**Author:** ![pcanal](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pcanal/32/12439_2.png) [@pcanal](https://root-forum.cern.ch/u/pcanal)\
**Post date:** [February 4, 2012, 5:23pm UTC](https://root-forum.cern.ch/t/linking-problem-to-libtree-so/13697/8 "2012-02-04T17:23:09Z")

</div>

Hi Nadjeh,

Can you load the file and read your TTree with the ROOT executable?`
root.exe -b -l 
root [] TFile f("yourfile.root");
root [] TTree *tree; f.GetObject("runTree",tree);`

Philippe

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [February 4, 2012, 6:19pm UTC](https://root-forum.cern.ch/t/linking-problem-to-libtree-so/13697/9 "2012-02-04T18:19:02Z")

</div>

Do you create an instance of TApplication in your main? If not, auto-loading of ROOT libraries will not work and you will need to load (some of) them manually, i.e. ‘gSystem-\>Load(“[libTree.so](http://libTree.so)”);’.  
Do you have the “/etc/root” subdirectory? If yes, you most probably have Ubuntu’s default version of ROOT installed, which may interfere with your “private” ROOT installation (in “/opt/root”) -\> “completely remove” all standard Ubuntu’s ROOT packages (using a “package manager”) - see also [url][ROOT 5.32/00 support](https://root-forum.cern.ch/t/root-5-32-00-support/13674/1)

---

<div class="post-metadata">

**Author:** ![ajafari](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@ajafari](https://root-forum.cern.ch/u/ajafari)\
**Post date:** [February 5, 2012, 10:57am UTC](https://root-forum.cern.ch/t/linking-problem-to-libtree-so/13697/10 "2012-02-05T10:57:43Z")

</div>

Hi Philippe,

> [@pcanal](#):
>
> Can you load the file and read your TTree with the ROOT executable?[code]

Here it is:

root [1] gSystem-\>Load(“libPhysics.so”);  
root [2] gSystem-\>Load(“~/lib/libToto.so”);  
root [3] TFile f(“~/work/samples/t-chan-Sync/1-TOPTREE.root”)  
root [4] TTree \*tree; f.GetObject(“runTree”,tree);  
root [5] tree-\>GetEntries()  
(const Long64\_t)1

The first two libraries I load so root recognizes my objects and does not warn about the missing dictionary.  
The rest seems fine.

Cheers,  
Nadjieh

---

<div class="post-metadata">

**Author:** ![ajafari](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@ajafari](https://root-forum.cern.ch/u/ajafari)\
**Post date:** [February 5, 2012, 11:06am UTC](https://root-forum.cern.ch/t/linking-problem-to-libtree-so/13697/11 "2012-02-05T11:06:27Z")

</div>

Hi Pepe,

[quote=“Pepe Le Pew”]Do you create an instance of TApplication in your main?  
[/quote]  
No I don’t.

[quote=“Pepe Le Pew”]  
If not, auto-loading of ROOT libraries will not work and you will need to load (some of) them manually, i.e. ‘gSystem-\>Load(“libTree.so”);’.[/quote]  
Strange! Is it because of ubuntu? I have never used TApplication and I didn’t experience any problem like this before.

> [@Pepe Le Pew](#):
>
> Do you have the “/etc/root” subdirectory?

No. The outcome of  
$l /etc/ | grep root  
command is empty. I also tried  
locate config-root and I got locate root-config  
/opt/root/bin/root-config  
/opt/root/cmake/scripts/root-config.in  
/opt/root/config/root-config.in  
/opt/root/man/man1/root-config.1  
Cheers,  
Nadjieh

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [February 5, 2012, 12:55pm UTC](https://root-forum.cern.ch/t/linking-problem-to-libtree-so/13697/12 "2012-02-05T12:55:19Z")

</div>

So, the problem is … lack of a TApplication (thus no auto-loading of ROOT libraries) AND a new linker type (“unused” libraries given to the linker stage are “stripped” because of the default “–as-needed” flag).  
You may try three solutions:

1. add an instance of TApplication in you main (I presume this is the preferred method):  
grep -r "TApplication " ${ROOTSYS}/test/\* ${ROOTSYS}/tutorials/\*
2. load additional required libraries manually (i.e. ‘gSystem-\>Load(“[libTree.so](http://libTree.so)”);’)
3. add the “–no-as-needed” flag to the linking stage of your application (something like “-Wl,–no-as-needed $(ROOTGLIBS)”)

---

<div class="post-metadata">

**Author:** ![ajafari](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/a/f08c70/32.png) [@ajafari](https://root-forum.cern.ch/u/ajafari)\
**Post date:** [February 6, 2012, 12:27pm UTC](https://root-forum.cern.ch/t/linking-problem-to-libtree-so/13697/13 "2012-02-06T12:27:11Z")

</div>

Hello Pepe,  
Thanks a lot for following this issue.  
I tried your first suggested option:

> [@Pepe Le Pew](#):
>
> 1. add an instance of TApplication in you main (I presume this is the preferred method):  
> grep -r "TApplication " {ROOTSYS}/test/\* {ROOTSYS}/tutorials/\*

and it worked 🙂

Cheers,  
Nadjieh

---

<div class="post-metadata">

**Author:** ![RaubkatzHimself](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/0ea827/32.png) [@RaubkatzHimself](https://root-forum.cern.ch/u/RaubkatzHimself)\
**Post date:** [December 13, 2017, 9:23am UTC](https://root-forum.cern.ch/t/linking-problem-to-libtree-so/13697/14 "2017-12-13T09:23:20Z")

</div>

Hy! I stumbled across the same Problem and I#m really to new to everything. Can you tell me exactly what to do??  
I just don’t know where to add for example the "-Wl,–no-as-needed " flag, do I have to add it in the compiler or where??  
I have a bash script to run run my application.
