Compiler Error when using TTreeReader

Hello!

I get a compiler error that seems to stem from initializing a TTreeReader object and I don’t know how to handle it:

$ rootCPP first_try2
/usr/bin/ld: first_try2.o: undefined reference to symbol '_ZN11TTreeReaderD1Ev'
/usr/local/lib/libTreePlayer.so: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status

rootCPP is an alias I defined in my .bashrc:

function rootCPP {
   g++ -std=gnu++11 -o $1.o $1.cc -c `root-config --cflags`
   g++ -std=gnu++11 -o $1.exe $1.o `root-config --libs`;
}

My google research suggested, that some libs are not linked correctly, but I couldn’t find anything specific and I’m not yet proficient enough with linux to understand the problem :frowning:

So far I never had any issues like this, are there any compatibility issues with TTreeReader?
I use a Fedora 23 OS and gcc version 5.3.1.

$gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/5.3.1/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --enable-bootstrap --enable-languages=c,c++,objc,obj-c++,fortran,ada,go,lto --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-shared --enable-threads=posix --enable-checking=release --enable-multilib --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-plugin --enable-initfini-array --disable-libgcj --with-isl --enable-libmpx --enable-gnu-indirect-function --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 5.3.1 20151207 (Red Hat 5.3.1-2) (GCC)

Try to add “-lTreePlayer”.

Hi,

it seems you need to link against libTreePlayer.so, i.e. adding

-l TreePlayer

to your linker invocation. The root-config utility does not provide this by default.
Just a curiosity about linux: try to invoke these commands

c++filt _ZN11TTreeReaderD1Ev
nm $ROOTSYS/lib/libTreePlayer.so |grep _ZN11TTreeReaderD1Ev

You will see that your are missing a destructor and that the library above “contains” the right symbol :wink:

Cheers,
Danilo

Thank you very much!
I’m still a greenhorn on linux, it would probably have taken me ages to find a solution :smiley:

I’m bumping this since I’ve experienced the same issue.

My project is built with cmake, so I first tried to load ROOT using

find_package(ROOT 6.04 REQUIRED COMPONENTS TreePlayer)

But that wouldn’t solve the issue. What’s weird is that libTreePlayer.so does seem to be present in ROOT_LIBRARIES

The only way to link successfully was to add:

find_library(ROOT_TREEPLAYER_LIBRARY TreePlayer HINTS ${ROOT_LIBRARY_DIR} REQUIRED)

And explicitly link the executable to the resulting ${ROOT_TREEPLAYER_LIBRARY}.

Is there perhaps a bug in FindROOT.cmake, that the first method didn’t work?