Compile ROOT libraries from command line

Hi,

I am working on some code from the past which has a mixing of fortran and c++.
Since I would like to use ROOT to plot and manage the histograms, but I don’t want to write again all the code, I tried to add some lines to load and write ROOT histos. The libraries I need are:

#include "TH1D.h"
#include "TFile.h"
#include "TObjArray.h"

I tried to compile the code modifying the Makefile as follows:

obj = (...some .o file names...)

opt = -g -O2 -m64  -Wall -fPIC
#opt = -O4

.f.o:
	gfortran -c $(opt) $?
.F.o:
	gfortran -c $(opt) $?
.cc.o:
	g++ -c $(opt) $?
hfit	:$(obj) hfit.cc
	g++ -D __MAIN__ hfit.cc $(opt) $(obj) \
	-I/cern/root/pro/include \
	-L/cern/2006/lib/ -L/usr/lib/gcc/x86_64-redhat-linux/4.3.2 \
	-L/cern/root/pro/lib \
	-lpacklib -lmathlib -lkernlib -lgfortran \
	-lCore -lCint -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree \
	-lRint -lPostscript -lMatrix -lPhysics -pthread -lm -ldl -rdynamic \
	-o hfit

But when I try to run

> make hfit

The compiler gives me the error

...
error: TH1D.h: No such file or directory
...
make: *** [hfit.o] Error 1

Searching in the forum I found that in root/test there is a Makefile to compile user-defined programs, but I don’t want to rewrite the Makefile, because I don’t want to get problems with the other pieces of code.

Can anybody help me?

It is likely that you forgot -I$ROOTSYS/include in your compilation step.

Rene

[quote=“brun”]It is likely that you forgot -I$ROOTSYS/include in your compilation step.
[/quote]

$ROOTSYS is actually pointing to /cern/root/pro

> $ROOTSYS bash: /cern/root/pro: is a directory

which I wrote explicitly into the Makefile.
However I just tried to write -I$ROOTSYS/include into the makefile and nothing changed.

Maurizio

Which version are you using? Could you check that $ROOTSYS/include/TH1D.h is indeed in your system?

Rene

I am using ROOT 5.22 compiled on linuxx8664gcc.
All the include files are where we expect them to be:

ll $ROOTSYS/include/TH1D.h 
-rw-r--r-- 1 xxx xxx 1237 2009-03-08 14:17 /cern/root/pro/include/TH1D.h

Usually I can compile code using ACLIC in ROOT.

Unfortunately this time all the code has been previously written to deal with ZEBRA files and I just wanted to add the option to work with ROOT histograms.

The old code compiles and runs fine.

Hi,

You makefile instruct to compile hfit.cc via the rule.cc.o: g++ -c $(opt) $?whereopt = -g -O2 -m64 -Wall -fPIC does NOT have -I$ROOTSYS/include

So the problem is likely that unwittingly you ended up with hfit.o being listed in $(obj):hfit :$(obj) hfit.cc

Cheers,
Philippe.

[quote=“pcanal”]Hi,

You makefile instruct to compile hfit.cc via the rule.cc.o: g++ -c $(opt) $?whereopt = -g -O2 -m64 -Wall -fPIC does NOT have -I$ROOTSYS/include

So the problem is likely that unwittingly you ended up with hfit.o being listed in $(obj):hfit :$(obj) hfit.cc

Cheers,
Philippe.[/quote]

Modifing

to

solved my problem.

Thank you!