# Link ROOT libraries in Garfield++

**URL:** <https://root-forum.cern.ch/t/link-root-libraries-in-garfield/19895>\
**Category:** Garfield++\
**Created:** [September 24, 2015, 4:11pm UTC](https://root-forum.cern.ch/t/link-root-libraries-in-garfield/19895 "2015-09-24T16:11:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![elia](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/278dde/32.png) [@elia](https://root-forum.cern.ch/u/elia)\
**Post date:** [September 24, 2015, 4:11pm UTC](https://root-forum.cern.ch/t/link-root-libraries-in-garfield/19895/1 "2015-09-24T16:11:34Z")

</div>

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:

```auto
/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:

```auto
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

```

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [September 24, 2015, 4:30pm UTC](https://root-forum.cern.ch/t/link-root-libraries-in-garfield/19895/2 "2015-09-24T16:30:34Z")

</div>

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 --…)

---

<div class="post-metadata">

**Author:** ![elia](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/278dde/32.png) [@elia](https://root-forum.cern.ch/u/elia)\
**Post date:** [September 24, 2015, 4:59pm UTC](https://root-forum.cern.ch/t/link-root-libraries-in-garfield/19895/3 "2015-09-24T16:59:37Z")

</div>

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`

---

<div class="post-metadata">

**Author:** ![Wile\_E\_Coyote](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/wile_e_coyote/32/12417_2.png) [@Wile\_E\_Coyote](https://root-forum.cern.ch/u/Wile_E_Coyote)\
**Post date:** [September 24, 2015, 5:03pm UTC](https://root-forum.cern.ch/t/link-root-libraries-in-garfield/19895/4 "2015-09-24T17:03:35Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![elia](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/e/278dde/32.png) [@elia](https://root-forum.cern.ch/u/elia)\
**Post date:** [September 24, 2015, 5:22pm UTC](https://root-forum.cern.ch/t/link-root-libraries-in-garfield/19895/5 "2015-09-24T17:22:05Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![system](https://root-forum.cern.ch/uploads/default/original/3X/e/f/efe4f24398fd8ffeb76bccb6ecc46d9d9c003376.png) [@system](https://root-forum.cern.ch/u/system)\
**Post date:** [June 21, 2018, 9:12am UTC](https://root-forum.cern.ch/t/link-root-libraries-in-garfield/19895/6 "2018-06-21T09:12:26Z")

</div>

Closed on June 21, 2018, 9:12am UTC

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