ROOT with GEANT4 in MAC OS X 10.5


I have just installed geant4 and root using the “fink” program in my MAC OS X 10.5 laptop.

I have tested the examples from G4 and they work fine, and I am also able to visualize them. I have also tested root and it works fine on its own: when I type “root” I can plot canvas and all the rest without problems.

The problem comes when I compile my simulation, which is done in Geant4 but gives as output a root file with root trees inside.

Usually one has to set the environment variables:
#export ROOTSYS=/Users/suarez/InstalledPrograms/root
#export PATH=$ROOTSYS/bin:$PATH

and it should work… but it doesn’t.

I get errors on compilation of the kind:

src/ error: TFile.h: No such file or directory
src/ error: TTree.h: No such file or directory
src/ error: TNamed.h: No such file or directory
src/ error: TF1.h: No such file or directory
src/ error: TH1F.h: No such file or directory

Like if the system would now know where to find this variables, or would not understand the environment variables that I had set before.

Any clues why is it so? In my linux compter it always worked.


When compiling with G4 code using ROOT classes, you must specify the -I$ROOTSYS/include in your include path.
We recommend using the following script in $ROOTSYS/bin to generate a string
that you can insert in your compiler directives, eg

g++ -c myapp.cxx `root-config --cflags`

Hi Rene,

I thought that this is what one includes in the makefile. My makefile is the following:

[code]# --------------------------------------------------------------

GNUmakefile for examples module. Gabriele Cosmo, 06/04/98.


name := main_polar
G4TARGET := $(name)
G4EXLIB := true

ifndef G4INSTALL
G4INSTALL = …/…/…

.PHONY: all
all: lib bin

CPPFLAGS += -pthread -I/Users/suarez/InstalledPrograms/root
ROOTLIBS = $(shell $(ROOTSYS)/bin/root-config --nonew --libs)

include $(G4INSTALL)/config/binmake.gmk[/code]

Aren’t this three lines (CPPFLAGS, ROOTLIBS, EXTRALIBS) responsible to link with ROOT?

I’ve checked that the addresses are right, but nevertheless I get the same error messages: “TFile.h: No such file or directory”

Thanks for your help,


Most like you need to replace


$(shell $(ROOTSYS)/bin/root-config --cflags)Cheers,

[Post corrected to replace --include with --cflags]


I’ve changed what you suggested in the makefile:

CPPFLAGS += -pthread $(shell $(ROOTSYS)/bin/root-config --include) ROOTLIBS = $(shell $(ROOTSYS)/bin/root-config --nonew --libs) EXTRALIBS := $(ROOTLIBS)

but now, in addition to the errors of not finding TTree, I get the following:

Unknown argument "--include"! Usage: root-config [--prefix[=DIR]] [--exec-prefix[=DIR]] [--version] [--cflags] [--auxcflags] [--ldflags] [--new] [--nonew] [--libs] [--glibs] [--bindir] [--libdir] [--incdir] [--noauxcflags] [--noauxlibs] [--noldflags] [--has-<feature>] [--arch] [--platform] [--dicttype] [--config] [--features] [--svn-revision] [--python-version] [--cc] [--cxx] [--f77] [--ld ][--help]

so I’ve tried something different:

CPPFLAGS += -pthread $(shell $(ROOTSYS)/bin/root-config --cflags) ROOTLIBS = $(shell $(ROOTSYS)/bin/root-config --nonew --libs) EXTRALIBS := $(ROOTLIBS)

It does work like this. Now I can run my code. The only issue is that it is terribly slow (compared with when I run it under my Linux machine). But I think that this is a completely different problem. :slight_smile:

Thank you very much for all your help.