Re: makefiles with root: a question

From: Paul Nilsson (paul.nilsson@kosufy.lu.se)
Date: Fri Mar 24 2000 - 17:50:09 MET


Hi there,

I have also encountered the problem with 'undefined references' when
trying to compile the root test programs as well as my own root
programs. I might have a solution to the problem.

The error messages started to appear when I switched to the latest gcc
package (2.95-2 [as of March 2k]) on a RedHat 6.0 system. The default
installation directories lie under /usr/local/. This means that any
older gcc/egcs distributions are not automatically overwritten/removed
unless they were installed in the same directories. It might be a good
idea to remove older versions before installing new. That was my
mistake.

On my system, I used the 2.91 egcs distribution that came with RedHat,
where e.g. the binaries were installed in /usr/bin. Keeping this
distribution lead to some kind of compiler conflict with the new
compiler which resulted in exactly the same error messages as you got
(see below). By removing the new gcc distribution, I restored the system
and the compilation runs like a dream.

Regards,
Paul Nilsson

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Paul B. Nilsson, Ph.D student,
Div. of Cosmic and Subatomic Physics, Lund University,
Solvegatan 14, SE-223 62 Lund, Sweden.
Phone: +46 46 222 47 67
Fax: +46 46 222 40 15
E-mail: paul@kosufy.lu.se
Homepage: http://www.kosufy.lu.se/staff/paul/
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Gilles Zalamansky and Masaharu Goto wrote:
> 
> I send you this email because I can't get through with compiling cint
> programs
> . May be you can help me.  In this case, I would be very grateful to
> you.
> 
> I use the pro version of root, on Linux redhat 6.
> 
> I always received those kind of error messages
> >make
> g++ -o corsaires corsaires.cc -I/cern/root/include -O -Wall -fPIC
> -I/cern/root/include -L/cern/root/lib -lNew -lCore -lCint -lHist -lGraf
> -lGraf3d
> -lGpad -lTree -lRint -lPostscript -lMatrix -lPhysics -lm -ldl -rdynamic
> corsairesObjC.o
> /tmp/ccAonME3.o: In function `main':
> /tmp/ccAonME3.o(.text+0x254): undefined reference to `TFile::TFile(char
> const
> *,
> char const *, char const *, int)'
> collect2: ld returned 1 exit status
> make: *** [corsaires] Error 1
> linstar5>
> 
> when I try to compile my cint program corsdaires.cc, with classes
> defined in
> corsairesObj.h
> 
> I send you corsaires.cc, corsairesObj.h (I simplfied them as much as
> possible
> for this mail),  my LinkDef.h and my Makefile:
> 
> -------------------------Corsaires.cc--------
> #include "corsairesObj.h"
> 
> ClassImp(Part)
> ClassImp(ShowerHeader)
> ClassImp(Event)
> 
> TROOT root(" "," ");
> 
> int main()
> {
> TFile *EvTFile=new TFile("a root file","RECREATE","a root file");
> EvTFile->Close();
> return 0;
> }
> 
> ----------------------------------------------
> -------------corsairesObj.h-------------------
> #ifndef RUNOBJ_H
> #define RUNOBJ_H
> #include <stdio.h>
> #include <stdlib.h>
> #include <string.h>
> #include <cstdlib>
> #include <iostream.h>
> #include "/cern/root/include/TFile.h"
> #include "/cern/root/include/TTree.h"
> #include "/cern/root/include/TROOT.h"
> #include "/cern/root/include/TObject.h"
> 
> class Part:public TObject
> {
> private:
> public:
> 
> Part(){};
> 
> ~Part(){};
> ClassDef(Part,1)
> };
> 
> class ShowerHeader:public TObject
> {
> private:
> public:
> 
> ShowerHeader(){};
> ~ShowerHeader(){};
> 
> ClassDef(ShowerHeader,1)
> };
> 
> class Event:public TObject
> {
> private:
> public:
> 
> ~Event(){};
> ClassDef(Event,1)
> };
> 
> #endif
> ---------------------------------------------
> 
> ---------------Makefile-----------------------
> ROOTCFLAGS    = $(shell root-config --cflags)
> ROOTLIBS      = $(shell root-config --libs)
> ROOTGLIBS     = $(shell root-config --glibs)
> 
> ROOTSYS=/cern/root
> # Linux with egcs
> CXX           = g++
> CXXFLAGS      =-I$(ROOTSYS)/include -O -Wall -fPIC
> LD            = g++
> LDFLAGS       = -g
> SOFLAGS       = -shared
> 
> CXXFLAGS     += $(ROOTCFLAGS)
> LIBS          = $(ROOTLIBS)
> GLIBS         = $(ROOTGLIBS)
> 
> all: corsaires
> clean:
>         rm *.o *C.*
> 
> corsairesObjC.cc: corsairesObj.h LinkDef.h
>         $(ROOTSYS)/bin/rootcint -f corsairesObjC.cc -c corsairesObj.h
> LinkDef.
> h
> corsairesObjC.o: corsairesObjC.cc
>         $(CXX) -c corsairesObjC.cc $(CXXFLAGS)
> 
> corsaires: corsaires.cc corsairesObjC.o
>         $(CXX) -o corsaires corsaires.cc $(CXXFLAGS) $(LIBS)
> corsairesObjC.o
> 
> ----------------------------------------------
> 
> -------------------Linkdef,h------------------
> #ifdef __CINT__
> 
> #pragma link off all globals;
> #pragma link off all classes;
> #pragma link off all functions;
> 
> #pragma link C++ class Part;
> #pragma link C++ class ShowerHeader;
> #pragma link C++ class Event;
> 
> #endif
> ----------------------------------------------
> 
> I type "make" in the directory in which all those files belong, and
> /cern/root/include is the right pass in my computer for the .h files
> Hello Rooters,
> 
> I get following question.  This is about building ROOT application.
> My speciality is limited on pure Cint, so would anybody answer his
> question?
> 
> Thank you
> Masaharu Goto
> 
> ==============================================================================
> 
> So my question is: Can you see what's missing in any of my files that
> explain
> for the error messages?
> 
> When I copy /root/test into a directory "test", and type "make" inside
> to
> compile Event.cxx, I also get an error:
> make
> g++ -O -Wall -fPIC -I/cern/root/include -c Event.cxx
> g++ -O -Wall -fPIC -I/cern/root/include -c EventDict.cxx
> g++ -O -Wall -fPIC -I/cern/root/include -c MainEvent.cxx
> g++ -shared -g Event.o EventDict.o -o libEvent.so
> g++ -g MainEvent.o Event.o EventDict.o -L/cern/root/lib -lNew -lCore
> -lCint
> -lHist -lGraf -lGraf3d -lGpad -lTree -lRint -lPostscript -lMatrix
> -lPhysics -l
> m -ldl -rdynamic -o Event
> MainEvent.o: In function `main':
> MainEvent.o(.text+0x746): undefined reference to `TFile::TFile(char
> const *,
> char const *, char const *, int)'
> MainEvent.o(.text+0xa15): undefined reference to `TFile::TFile(char
> const *,
> char const *, char const *, int)'
> MainEvent.o(.text+0xb3e): undefined reference to
> `TDirectory::TDirectory(char
> const *, char const *, char const *)'
> collect2: ld returned 1 exit status
> make: *** [Event] Error 1
> 
> so probably it's an installation problem, but I can't see which.
> 
> With my best regards,
> Gilles Zalamansky
> University of leeds, UK



This archive was generated by hypermail 2b29 : Tue Jan 02 2001 - 11:50:22 MET