Error while compiling garfroot.C

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!

#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);

}

The makefile is given below.

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.

Hi,

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

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

Cheers,
D

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 :

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

Hi,

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

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

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

compiles with this line:

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

Cheers,
D

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 ?

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

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:

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

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

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.

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.

Hi mato. The code

#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.

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.

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