# Error while compiling garfroot.C

**URL:** <https://root-forum.cern.ch/t/error-while-compiling-garfroot-c/21955>\
**Category:** Garfield++\
**Created:** [September 28, 2016, 2:46pm UTC](https://root-forum.cern.ch/t/error-while-compiling-garfroot-c/21955 "2016-09-28T14:46:39Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![B.Bijay](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/85e7bf/32.png) [@B.Bijay](https://root-forum.cern.ch/u/B.Bijay)\
**Post date:** [September 28, 2016, 2:46pm UTC](https://root-forum.cern.ch/t/error-while-compiling-garfroot-c/21955/1 "2016-09-28T14:46:39Z")

</div>

Hi. I am trying to compile garfroot.C in order to use the Garfield++ classes interactively from within the ROOT shell. When I type “$ make garfroot” in command prompt, the following errors come out and the compilation stops. I really appreciate any help!

```auto
#include <iostream>
#include <fstream>
#include <cmath>

#include <TROOT.h>
#include <TRint.h>

#include "Plotting.hh"

int main(int argc, char * argv[]) {

  std::cout << "Welcome to Garfield++\n";
  Garfield::plottingEngine.SetDefaultStyle();
  
  TRint* app = new TRint("Garfield", &argc, argv, 0, 0);
  
  app->Run(kTRUE);

}

```

> [@](#):
>
> biplabbijay@Jenifer:~/garfield/GarfRoot$ make garfroot  
> `root-config --cxx` `root-config --cflags` -I/home/biplabbijay/garfield/Include -I/home/biplabbijay/garfield/Heed -fno-common -fPIC -O3 -W -Wall -Wextra -Wno-long-long -g -o garfroot garfroot.C -L/home/biplabbijay/garfield/Library -Wl,–whole-archive -lGarfield -Wl,–no-whole-archive -lgfortran `root-config --evelibs`  
> /home/biplabbijay/garfield/Library/libGarfield.a(Medium.o): In function `Garfield::Medium::GetElectronMomentum(double, double&, double&, double&, int&)': Medium.cc:(.text+0xf014): undefined reference to `TRandom3::Rndm(int)’  
> Medium.cc:(.text+0xf05b): undefined reference to `TRandom3::Rndm(int)' /home/biplabbijay/garfield/Library/libGarfield.a(Medium.o): In function `Garfield::Medium::GetElectronCollision(double, int&, int&, double&, double&, double&, double&, int&, int&, int&)‘:  
> Medium.cc:(.text+0xf14a): undefined reference to `TRandom3::Rndm(int)' Medium.cc:(.text+0xf191): undefined reference to `TRandom3::Rndm(int)’  
> /home/biplabbijay/garfield/Library/libGarfield.a(AvalancheMicroscopic.o): In function `Garfield::AvalancheMicroscopic::TransportPhoton(double, double, double, double, double)': AvalancheMicroscopic.cc:(.text+0x1fcc): undefined reference to `TRandom3::Rndm(int)’  
> /home/biplabbijay/garfield/Library/libGarfield.a(AvalancheMicroscopic.o):AvalancheMicroscopic.cc:(.text+0x2015): more undefined references to `TRandom3::Rndm(int)' follow /home/biplabbijay/garfield/Library/libGarfield.a(RandomEngineRoot.o): In function `Garfield::RandomEngineRoot::Seed(unsigned int)‘:  
> RandomEngineRoot.cc:(.text+0x135): undefined reference to `TRandom3::SetSeed(unsigned int)' /home/biplabbijay/garfield/Library/libGarfield.a(RandomEngineRoot.o): In function `Garfield::RandomEngineRoot::Draw()’:  
> RandomEngineRoot.cc:(.text.\_ZN8Garfield16RandomEngineRoot4DrawEv[\_ZN8Garfield16RandomEngineRoot4DrawEv]+0x12): undefined reference to `TRandom3::Rndm(int)' /home/biplabbijay/garfield/Library/libGarfield.a(ViewFEMesh.o): In function `Garfield::ViewFEMesh::IsInPolygon(double, double, std::vector\<double, std::allocator \>&, std::vector\<double, std::allocator \>&, bool&)‘:  
> ViewFEMesh.cc:(.text+0x7036): undefined reference to `TRandom3::Rndm(int)' ViewFEMesh.cc:(.text+0x7071): undefined reference to `TRandom3::Rndm(int)’  
> /home/biplabbijay/garfield/Library/libGarfield.a(AvalancheMC.o): In function `Garfield::AvalancheMC::DriftLine(double, double, double, double, int, bool)': AvalancheMC.cc:(.text+0x2666): undefined reference to `TRandom3::Rndm(int)’  
> AvalancheMC.cc:(.text+0x2686): undefined reference to `TRandom3::Rndm(int)' /home/biplabbijay/garfield/Library/libGarfield.a(AvalancheMC.o):AvalancheMC.cc:(.text+0x3051): more undefined references to `TRandom3::Rndm(int)’ follow  
> collect2: error: ld returned 1 exit status  
> makefile:28: recipe for target ‘garfroot’ failed  
> make: \*\*\* [garfroot] Error 1  
> biplabbijay@Jenifer:~/garfield/GarfRoot$

The makefile is given below.

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

# Compiler (and Linker)
CXX = `root-config --cxx`

# Compiler (and Linker) flags
CXXFLAGS = `root-config --cflags`
CXXFLAGS += -I$(INCDIR) -I$(HEEDDIR)
# Code Generation and Optimization flags
CXXFLAGS += -fno-common -fPIC -O3
# Warning flags
CXXFLAGS += -W -Wall -Wextra -Wno-long-long
# Debug flags
CXXFLAGS += -g

# Libraries (note: the order matters)
LDLIBS = -L$(LIBDIR) -Wl,--whole-archive -lGarfield -Wl,--no-whole-archive
# Fortran libraries
LDLIBS += -lgfortran
# ROOT libraries
LDLIBS += `root-config --evelibs`

garfroot: garfroot.C
	$(CXX) $(CXXFLAGS) -o $@ $^ $(LDLIBS)

```

P.S. I am using ubuntu 16.04, Garfield++ and ROOT version 6.07/07.

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [September 28, 2016, 7:17pm UTC](https://root-forum.cern.ch/t/error-while-compiling-garfroot-c/21955/2 "2016-09-28T19:17:50Z")

</div>

Hi,

you are missing symbols at link time from root libraries. Try to update your CXXFLAGS:

```auto
CXXFLAGS = `root-config --cflags --libs`
```

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![B.Bijay](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/85e7bf/32.png) [@B.Bijay](https://root-forum.cern.ch/u/B.Bijay)\
**Post date:** [September 28, 2016, 10:24pm UTC](https://root-forum.cern.ch/t/error-while-compiling-garfroot-c/21955/3 "2016-09-28T22:24:13Z")

</div>

Hi. Thanks for your reply. I have updated the CXXFLAGS as per your suggestion. But the problem still persists. The make file and the errors are given below :

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

# Compiler (and Linker)
CXX = `root-config --cxx`

# Compiler (and Linker) flags
CXXFLAGS = `root-config --cflags --libs`
CXXFLAGS += -I$(INCDIR) -I$(HEEDDIR)
# Code Generation and Optimization flags
CXXFLAGS += -fno-common -fPIC -O3
# Warning flags
CXXFLAGS += -W -Wall -Wextra -Wno-long-long
# Debug flags
CXXFLAGS += -g

# Libraries (note: the order matters)
LDLIBS = -L$(LIBDIR) -Wl,--whole-archive -lGarfield -Wl,--no-whole-archive
# Fortran libraries
LDLIBS += -lgfortran
# ROOT libraries
LDLIBS += `root-config --evelibs`

garfroot: garfroot.C
	$(CXX) $(CXXFLAGS) -o $@ $^ $(LDLIBS)
```

```auto
biplabbijay@Jenifer:~/garfield/GarfRoot$ make garfroot
`root-config --cxx` `root-config --cflags --libs` -I/home/biplabbijay/garfield/Include -I/home/biplabbijay/garfield/Heed -fno-common -fPIC -O3 -W -Wall -Wextra -Wno-long-long -g -o garfroot garfroot.C -L/home/biplabbijay/garfield/Library -Wl,--whole-archive -lGarfield -Wl,--no-whole-archive -lgfortran `root-config --evelibs`
/home/biplabbijay/garfield/Library/libGarfield.a(Medium.o): In function `Garfield::Medium::GetElectronMomentum(double, double&, double&, double&, int&)':
Medium.cc:(.text+0xf014): undefined reference to `TRandom3::Rndm(int)'
Medium.cc:(.text+0xf05b): undefined reference to `TRandom3::Rndm(int)'
/home/biplabbijay/garfield/Library/libGarfield.a(Medium.o): In function `Garfield::Medium::GetElectronCollision(double, int&, int&, double&, double&, double&, double&, int&, int&, int&)':
Medium.cc:(.text+0xf14a): undefined reference to `TRandom3::Rndm(int)'
Medium.cc:(.text+0xf191): undefined reference to `TRandom3::Rndm(int)'
/home/biplabbijay/garfield/Library/libGarfield.a(AvalancheMicroscopic.o): In function `Garfield::AvalancheMicroscopic::TransportPhoton(double, double, double, double, double)':
AvalancheMicroscopic.cc:(.text+0x1fcc): undefined reference to `TRandom3::Rndm(int)'
/home/biplabbijay/garfield/Library/libGarfield.a(AvalancheMicroscopic.o):AvalancheMicroscopic.cc:(.text+0x2015): more undefined references to `TRandom3::Rndm(int)' follow
/home/biplabbijay/garfield/Library/libGarfield.a(RandomEngineRoot.o): In function `Garfield::RandomEngineRoot::Seed(unsigned int)':
RandomEngineRoot.cc:(.text+0x135): undefined reference to `TRandom3::SetSeed(unsigned int)'
/home/biplabbijay/garfield/Library/libGarfield.a(RandomEngineRoot.o): In function `Garfield::RandomEngineRoot::Draw()':
RandomEngineRoot.cc:(.text._ZN8Garfield16RandomEngineRoot4DrawEv[_ZN8Garfield16RandomEngineRoot4DrawEv]+0x12): undefined reference to `TRandom3::Rndm(int)'
/home/biplabbijay/garfield/Library/libGarfield.a(ViewFEMesh.o): In function `Garfield::ViewFEMesh::IsInPolygon(double, double, std::vector<double, std::allocator<double> >&, std::vector<double, std::allocator<double> >&, bool&)':
ViewFEMesh.cc:(.text+0x7036): undefined reference to `TRandom3::Rndm(int)'
ViewFEMesh.cc:(.text+0x7071): undefined reference to `TRandom3::Rndm(int)'
/home/biplabbijay/garfield/Library/libGarfield.a(AvalancheMC.o): In function `Garfield::AvalancheMC::DriftLine(double, double, double, double, int, bool)':
AvalancheMC.cc:(.text+0x2666): undefined reference to `TRandom3::Rndm(int)'
AvalancheMC.cc:(.text+0x2686): undefined reference to `TRandom3::Rndm(int)'
/home/biplabbijay/garfield/Library/libGarfield.a(AvalancheMC.o):AvalancheMC.cc:(.text+0x3051): more undefined references to `TRandom3::Rndm(int)' follow
collect2: error: ld returned 1 exit status
makefile:28: recipe for target 'garfroot' failed
make: *** [garfroot] Error 1
biplabbijay@Jenifer:~/garfield/GarfRoot$ 

```

Do I have to add anything else ?

---

<div class="post-metadata">

**Author:** ![Danilo](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/danilo/32/34528_2.png) [@Danilo](https://root-forum.cern.ch/u/Danilo)\
**Post date:** [September 29, 2016, 4:52am UTC](https://root-forum.cern.ch/t/error-while-compiling-garfroot-c/21955/4 "2016-09-29T04:52:45Z")

</div>

Hi,

no. What version of ROOT are you using?  
Note that this trivial example:

```auto
#include "TRandom.h"
#include <iostream>

int main(){
  TRandom r;
  std::cout << r.Rndm(4) << std::endl;
  return 0;
 }
```

compiles with this line:

```auto
g++ -o test test.cpp `root-config --cflags --libs`
```

Cheers,  
D

---

<div class="post-metadata">

**Author:** ![B.Bijay](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/85e7bf/32.png) [@B.Bijay](https://root-forum.cern.ch/u/B.Bijay)\
**Post date:** [September 29, 2016, 5:40am UTC](https://root-forum.cern.ch/t/error-while-compiling-garfroot-c/21955/5 "2016-09-29T05:40:58Z")

</div>

Thank you for your response. I am using root 6.07/07. I dont know why so many problems are happening. May be it is because of Ubuntu 16.04 ?

---

<div class="post-metadata">

**Author:** ![mato](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mato/32/12317_2.png) [@mato](https://root-forum.cern.ch/u/mato)\
**Post date:** [September 29, 2016, 6:51am UTC](https://root-forum.cern.ch/t/error-while-compiling-garfroot-c/21955/6 "2016-09-29T06:51:36Z")

</div>

The missing symbol is in fact an inline that you be resolved automatically.

```auto
class TRandom : public ROOT::Math::TRandomEngine, public TNamed {
 virtual Double_t Rndm(Int_t ) { return Rndm(); }
 ...
 };
```

And by looking at the Garfield code it is not used (at least on the version I had a look). It is very strange.

Can you ran the following code in your system:

```auto
#include "TRandom3.h"
#include <iostream>

int main(){
  TRandom3 r;
  std::cout << r.Rndm() << std::endl;
  return 0;
 }
```

---

<div class="post-metadata">

**Author:** ![mato](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/mato/32/12317_2.png) [@mato](https://root-forum.cern.ch/u/mato)\
**Post date:** [September 29, 2016, 7:00am UTC](https://root-forum.cern.ch/t/error-while-compiling-garfroot-c/21955/7 "2016-09-29T07:00:46Z")

</div>

The only logical explanation is that the Garfield library was not build (in fact compiled) with the same version of ROOT that you try to use now. So the symbol was a real symbol, and now is a inline.

---

<div class="post-metadata">

**Author:** ![B.Bijay](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/85e7bf/32.png) [@B.Bijay](https://root-forum.cern.ch/u/B.Bijay)\
**Post date:** [September 29, 2016, 9:18am UTC](https://root-forum.cern.ch/t/error-while-compiling-garfroot-c/21955/8 "2016-09-29T09:18:49Z")

</div>

Thanks Mato. I think you are right. I installed the latest version of root after installing Garfield. I will check all these facts and let you know. Thank you very much.

---

<div class="post-metadata">

**Author:** ![B.Bijay](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/b/85e7bf/32.png) [@B.Bijay](https://root-forum.cern.ch/u/B.Bijay)\
**Post date:** [September 29, 2016, 9:30am UTC](https://root-forum.cern.ch/t/error-while-compiling-garfroot-c/21955/9 "2016-09-29T09:30:36Z")

</div>

Hi mato. The code

```auto
#include "TRandom3.h"
#include <iostream>

int main(){
  TRandom3 r;
  std::cout << r.Rndm() << std::endl;
  return 0;
 }

```

can be compiled in my system by the following command.

```auto
g++ -o test test.C `root-config --cflags --libs`
```

I think I have to rebuild Garfield++ . I will let you know if it will solve the problem or not. Thanks again.

---

<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, 11:40am UTC](https://root-forum.cern.ch/t/error-while-compiling-garfroot-c/21955/10 "2018-06-21T11:40:59Z")

</div>

Closed on June 21, 2018, 11:40am UTC

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