Undefined reference to TCanvas in Ubuntu 12.04

My analysis code which uses list of root files (data) and creates Histograms on a canvas. The code was developed by group on OpenSUSE. When I copied the same code to my Ubuntu 12.04 laptop and tried to run it but it didn’t work. The problem is with default linking of Ubuntu (as I understand from previous communication in this forum).

The error looks as following:

$ make
g++ -g -o FBBA FBBA.o  libFBBAnal.so  -L../FBRun libFBRun.so\
		-L/usr/local/root/lib -lRint -L/usr/local/root/lib -lGui -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic -m64 -L/usr/local/root/lib -lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -pthread -lm -ldl -rdynamic -lGpad -lHist -lGraf -lGraf3d -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lRIO -lNet -lThread -lCore -lCint -pthread -lm -ldl -rdynamic  -lTMVA -lMinuit -lXMLIO -lMLP -lTreePlayer -L/usr/lib64/ -lstdc++
libFBBAnal.so: undefined reference to `TCanvas::TCanvas(char const*, char const*, int, int, int, int)'
collect2: ld returned 1 exit status
make: *** [FBBA] Error 1

I made a test by removing all need of TCanvas in the code and it worked without error. But I do not know how to solve this issue, I really need TCanvas. The main file of the code is attached (sorry, no stand alone code since i don’t know how to make it small).

FBBAnal.cxx (14.8 KB)

Why are you putting the library several time in the link command ?
Are you ROOT library really in /usr/local/root/lib ?
Have you defined $ROOTSYS ?
Only TCanvas is causing problem ? The other ROOT objects you are using are fine ?

@ Couet
I didn’t put the libraries intentionally many times. Infact I am not good at coding, as long as it works, I do not bother. Here the code was working in OpenSUSE, I copied and tried to run in Ubuntu. I attach here the Makefile, just incase you want to have more hint.

Yes my root libraries are in “/usr/local/root/lib”

Defining $ROOTSYS , sorry no idea.

And yes, only TCanvas is creating problem, for example other things I defined are fine, TH2F and TGraph are working fine.

Where ?

Oops, sorry forgot to attach. Here you go !
Makefile.txt (1.05 KB)

can you provide FBBAnal.h ?

sure ! here you go !
FBBAnal.h (1.96 KB)

I am missing also FBGeometry.h

oki, here !
FBGeometry.h (2.87 KB)

Can you send me all the includes I need ?

here is an other one missing:

In file included from FBBAnal.cxx:2:
./FBBAnal.h:15:10: fatal error: 'ClassName.h' file not found
#include "ClassName.h"

utility.h (980 Bytes)
ClassName.h (158 Bytes)

not yet there:

./ClassName.h:4:10: fatal error: 'BBase.h' file not found
#include "BBase.h"

Following link has the minimum required folder of 4.4 MB to reproduce this error. I have shared on Dropbox via folowing link:
in the folder following three commands:
make clean
make chain

PS: I attach also BBase.h
BBase.h (16.4 KB)

do you also get :

In file included from FBBAnal.cxx:2:
./FBBAnal.h:58:10: warning: 'FBBAnal::Init' hides overloaded virtual function [-Woverloaded-virtual]
  void   Init();

No I don’t get such warning !

SOLVED: (simply linker issue of Ubuntu, we have to manualy link root libraries in order to solve such problem)
I simply added the $(LIBS) at the end of the line where “libFBBAnal.so” is mentioned (or created or linked… whatever is does there) in the Make-macro file. Make-macro is simply the Macro for Makefile.

NOTE that LIBS := $(shell root-config --libs) in my Makefile.

So the old line (with error):

libFBBAnal.so: $(FBBRO) $(FBBRDO) @$(MAKELIB) $(PLATFORM) $(LD) "$(LDFLAGS)" \ "$(SOFLAGS)" libFBBAnal.$(SOEXT) $@ "$(FBBRO) $(FBBRDO) "

And the new line (no error):

libFBBAnal.so: $(FBBRO) $(FBBRDO) @$(MAKELIB) $(PLATFORM) $(LD) "$(LDFLAGS)" \ "$(SOFLAGS)" libFBBAnal.$(SOEXT) $@ "$(FBBRO) $(FBBRDO) $(LIBS)"

Thanks a lot !

SOLVED: good :slight_smile: