Link ROOT libraries in Garfield++

Hi, I’m using Garfield++ to get a plot of the electric field inside a drift chamber. Garfield++ call some ROOT graphic libraries to do that, and I receive the following errors when I try to compile:

/home/roberto/garfield/Library/libGarfield.a(ViewField.o): In function `Garfield::ViewField::CreateFunctionWeightingField()':
ViewField.cc:(.text+0x32e9): undefined reference to `gROOT'
ViewField.cc:(.text+0x3786): undefined reference to `TF1::CreateFromFunctor(char const*, int)'
/home/roberto/garfield/Library/libGarfield.a(ViewField.o): In function `Garfield::ViewField::CreateProfileFunction()':
ViewField.cc:(.text+0x4859): undefined reference to `gROOT'
ViewField.cc:(.text+0x4ca9): undefined reference to `TF1::CreateFromFunctor(char const*, int)'
/home/roberto/garfield/Library/libGarfield.a(ViewField.o): In function `Garfield::ViewField::CreateFunction()':
ViewField.cc:(.text+0x59c9): undefined reference to `gROOT'
ViewField.cc:(.text+0x5e66): undefined reference to `TF1::CreateFromFunctor(char const*, int)'
/home/roberto/garfield/Library/libGarfield.a(ViewMedium.o): In function `Garfield::ViewMedium::AddFunction(double, double, double, double, bool, std::string, std::string, int, char, double, double, double)':
ViewMedium.cc:(.text+0x13a3): undefined reference to `gROOT'
ViewMedium.cc:(.text+0x18aa): undefined reference to `TF1::CreateFromFunctor(char const*, int)'
collect2: error: ld returned 1 exit status
make: *** [gasfile] Error 1

I think that the compiler can’t find the library TF1.h that is a ROOT’s graphic library, but I linked ROOT’s libraries in the makefile.
This is my makefile:

OBJDIR = $(GARFIELD_HOME)/Object
SRCDIR = $(GARFIELD_HOME)/Source
INCDIR = $(GARFIELD_HOME)/Include
HEEDDIR = $(GARFIELD_HOME)/Heed
LIBDIR = $(GARFIELD_HOME)/Library

# Compiler flags
CXX = `root-config --cxx`
CFLAGS = `root-config --cflags` \
	-O3 -W -Wall -Wextra -Wno-long-long \
	-fno-common \
	-I$(INCDIR) -I$(HEEDDIR)

# Debug flags
# CFLAGS += -g

LDFLAGS = -L$(LIBDIR) -lGarfield
LDFLAGS += `root-config --glibs` -lGeom -lgfortran -lm

gasfile: gasfile2.C
	$(CXX) $(CFLAGS) -c gasfile2.C
	$(CXX) $(CFLAGS) -o gasfile2 gasfile2.o $(LDFLAGS)
	rm gasfile2.o

Maybe you could post the full output of the linking step (i.e. including the line “$(CXX) $(CFLAGS) -o gasfile2 gasfile2.o $(LDFLAGS)”) and the output of:
root-config --cxx
root-config --cflags
root-config --glibs

Maybe you could also try to replace all root-config --... with $(shell root-config --…)

Thanks, this is the full output of make command:

roberto@roberto-HP-Pavilion-dv6-Notebook-PC:~/Scrivania/Garfield$ make `root-config --cxx` `root-config --cflags` -O3 -W -Wall -Wextra -Wno-long-long -fno-common -I/home/roberto/garfield/Include -I/home/roberto/garfield/Heed -c gasfile2.C `root-config --cxx` `root-config --cflags` -O3 -W -Wall -Wextra -Wno-long-long -fno-common -I/home/roberto/garfield/Include -I/home/roberto/garfield/Heed -o gasfile2 gasfile2.o -L/home/roberto/garfield/Library -lGarfield `root-config --glibs` -lGeom -lgfortran -lm /home/roberto/garfield/Library/libGarfield.a(ViewField.o): In function `Garfield::ViewField::CreateFunctionWeightingField()': ViewField.cc:(.text+0x32e9): undefined reference to `gROOT' ViewField.cc:(.text+0x3786): undefined reference to `TF1::CreateFromFunctor(char const*, int)' /home/roberto/garfield/Library/libGarfield.a(ViewField.o): In function `Garfield::ViewField::CreateProfileFunction()': ViewField.cc:(.text+0x4859): undefined reference to `gROOT' ViewField.cc:(.text+0x4ca9): undefined reference to `TF1::CreateFromFunctor(char const*, int)' /home/roberto/garfield/Library/libGarfield.a(ViewField.o): In function `Garfield::ViewField::CreateFunction()': ViewField.cc:(.text+0x59c9): undefined reference to `gROOT' ViewField.cc:(.text+0x5e66): undefined reference to `TF1::CreateFromFunctor(char const*, int)' /home/roberto/garfield/Library/libGarfield.a(ViewMedium.o): In function `Garfield::ViewMedium::AddFunction(double, double, double, double, bool, std::string, std::string, int, char, double, double, double)': ViewMedium.cc:(.text+0x13a3): undefined reference to `gROOT' ViewMedium.cc:(.text+0x18aa): undefined reference to `TF1::CreateFromFunctor(char const*, int)' collect2: error: ld returned 1 exit status make: *** [gasfile] Error 1

The output of others command:

roberto@roberto-HP-Pavilion-dv6-Notebook-PC:~/Scrivania/Garfield$ root-config --cxx g++

roberto@roberto-HP-Pavilion-dv6-Notebook-PC:~/Scrivania/Garfield$ root-config --cflags -pthread -std=c++11 -Wno-deprecated-declarations -m64 -I/home/roberto/root/include

roberto@roberto-HP-Pavilion-dv6-Notebook-PC:~/Scrivania/Garfield$ root-config --glibs -L/home/roberto/root/lib -lGui -lCore -lRIO -lNet -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lMathCore -lThread -lMultiProc -pthread -lm -ldl -rdynamic

Are you sure that your Garfield++ library has been compiled with the same ROOT version that you try to use now?
I actually suspect that your Garfield++ library has been compiled with ROOT 5.x and you try to use it now with ROOT 6.x.

Yes, I’ve recently updated my ROOT version, but I’ve forgot to recompile Garfield++. Now it works, thank you :smiley:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.