# Strange error when compiling program

**URL:** <https://root-forum.cern.ch/t/strange-error-when-compiling-program/13962>\
**Category:** ROOT\
**Created:** [March 13, 2012, 8:37am UTC](https://root-forum.cern.ch/t/strange-error-when-compiling-program/13962 "2012-03-13T08:37:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![riklund](https://root-forum.cern.ch/letter_avatar_proxy/v4/letter/r/ee59a6/32.png) [@riklund](https://root-forum.cern.ch/u/riklund)\
**Post date:** [March 13, 2012, 8:37am UTC](https://root-forum.cern.ch/t/strange-error-when-compiling-program/13962/1 "2012-03-13T08:37:05Z")

</div>

Hi!  
I’m trying to compile a program which is using some ROOT libraries under Ubuntu 11.10 (x86\_64). However, I get the following errors:

```auto
cc `root-config --ldflags --libs` dumproot.o -o dumproot
dumproot.o: In function `main':
dumproot.cc:(.text+0x89): undefined reference to `TFile::TFile(char const*, char const*, char const*, int)'
dumproot.cc:(.text+0xad): undefined reference to `TTree::TTree(char const*, char const*, int)'
dumproot.cc:(.text+0x4f4): undefined reference to `TFile::Write(char const*, int, int)'
dumproot.cc:(.text+0x508): undefined reference to `TFile::Close(char const*)'
dumproot.cc:(.text+0x51c): undefined reference to `TFile::~TFile()'
dumproot.cc:(.text+0x53a): undefined reference to `TObject::operator delete(void*)'
dumproot.cc:(.text+0x551): undefined reference to `TFile::~TFile()'
dumproot.o: In function `__static_initialization_and_destruction_0(int, int)':
dumproot.cc:(.text+0x599): undefined reference to `TVersionCheck::TVersionCheck(int)'
dumproot.o: In function `TObject::operator new(unsigned long)':
dumproot.cc:(.text._ZN7TObjectnwEm[TObject::operator new(unsigned long)]+0x14): undefined reference to `TStorage::ObjectAlloc(unsigned long)'
dumproot.o:(.eh_frame+0x4b): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
make: *** [dumproot] Error 1
```

I have tried to reinstall root, both from downloading the already compiled version from the root website and from checking out and comipling the source code from the root website. However this did not affect the error, and I have currently run out of ideas to the cause. Does anybody know what could be causing these errors?

The makefile looks like this:

```auto
CXXFLAGS += `root-config --cflags`
LDFLAGS += `root-config --ldflags --libs`

all: dumproot

dumproot.o: dumproot.cc

dumproot: dumproot.o

clean:
	rm *.o dumproot
```

and the commands root-config works with the given flags.

The sourcecode looks like this:

```auto
#define NUMBER_OF_TUBES 40
#define str(x) #x
#define glue(a,b,c) a ## b ## c

#include <stdlib.h>
#include <stdio.h>

#include "TFile.h"
#include "TTree.h"

struct EventHit
{
  double time;

  float UFSP;
  float LFSP;
  float BSP;
  float Ge;

  float DET[NUMBER_OF_TUBES]; // energy in detector
};

struct Event
{
  int eventno;
  int A;
  int Z;

  EventHit hit[3]; // 0 normally implantation, 1 decay, 2 spurious
};

int main(int argc, char **argv)
{
  if (argc < 3)
    {
      fprintf (stderr,"Usage: %s <infile.txt> <outfile.root>\n",argv[0]);
      exit(1);
    }
  
  TFile hfile(argv[2],"RECREATE");
  
  // Create a ROOT Tree
  
  TTree *tree = new TTree("T","Simulation result.");
  
  Event event;
  
  // Create branches.
  
  tree->Branch("event", &event.eventno,
	       "eventno/I:A/I:Z/I");
  
  //hopefully implantation.
  tree->Branch("hit1", &event.hit[0].time,
	       str(glue(h1T/D:h1UFSP/F:h1LFSP/F:h1BSP/F:h1Ge/F:h1DET[,NUMER_OF_TUBES,]/F)));
  //hopefully decay.
  tree->Branch("hit2", &event.hit[1].time,
	       str(glue(h2T/D:h2UFSP/F:h2LFSP/F:h2BSP/F:h2Ge/F:h2DET[,NUMER_OF_TUBES,]/F)));
  //some other decay?
  tree->Branch("hit2", &event.hit[2].time,
	       str(glue(h3T/D:h3UFSP/F:h3LFSP/F:h3BSP/F:h3Ge/F:h2DET[,NUMER_OF_TUBES,]/F)));
  
  FILE * inputFile = fopen(argv[1],"r");
  if(inputFile==NULL)
    {
      fprintf (stderr,"Could not open input file, exiting.");
      exit(1);
    }
  
  int currentHitPtr=0;
  while(!feof(inputFile))
    {
      int tmpEventNo, tmpA, tmpZ;
      double tmpTime;
      float tmpUFSP, tmpLFSP, tmpBSP, tmpGe;
      float tmpTube[NUMBER_OF_TUBES];
      
      //event# Z A time upper lower back Ge Tubes[0-39]
      fscanf(inputFile,"%d %d %d",&tmpEventNo, &tmpA, &tmpZ);
      
      fscanf(inputFile, "%le", &tmpTime);
      
      fscanf(inputFile,"%e %e %e %e", &tmpUFSP, &tmpLFSP, &tmpBSP, &tmpGe);
      
      for(int i = 0; i<NUMBER_OF_TUBES; i++)
	{
	  fscanf(inputFile,"%e",&tmpTube[i]);
	}
      
      if(event.eventno!=tmpEventNo) //Create new event.
	{
	  tree->Fill();
	  currentHitPtr=0;
	}
      if(currentHitPtr==0)
	{
	  memset(&event,0,sizeof(event));
	}
      if(currentHitPtr<2)
	{
	  event.eventno=tmpEventNo;
	  event.A = tmpA;
	  event.Z = tmpZ;
	  event.hit[currentHitPtr].time=tmpTime;
	  event.hit[currentHitPtr].UFSP=tmpUFSP;
	  event.hit[currentHitPtr].LFSP=tmpLFSP;
	  event.hit[currentHitPtr].BSP=tmpBSP;
	  event.hit[currentHitPtr].Ge=tmpGe;
	  for(int i = 0; i<NUMBER_OF_TUBES; i++)
	    {
	      event.hit[currentHitPtr].DET[i]=tmpTube[i];
	    }	  
	}
      ++currentHitPtr;
    }
  
  tree->Fill();
  
  fclose(inputFile);
  hfile.Write();
  hfile.Close();
  return 0;
}
```

---

<div class="post-metadata">

**Author:** ![Pepe\_Le\_Pew](https://root-forum.cern.ch/user_avatar/root-forum.cern.ch/pepe_le_pew/32/12365_2.png) [@Pepe\_Le\_Pew](https://root-forum.cern.ch/u/Pepe_Le_Pew)\
**Post date:** [March 13, 2012, 8:43am UTC](https://root-forum.cern.ch/t/strange-error-when-compiling-program/13962/2 "2012-03-13T08:43:39Z")

</div>

```auto
See also [url]https://root-forum.cern.ch/t/compilation-problem-of-stand-alone-program/13901/1
```

See also [url][Compilation problem of stand alone program](https://root-forum.cern.ch/t/compilation-problem-of-stand-alone-program/13901/1)
