Re: [ROOT] Linking problem with private Class

From: Rene Brun (Rene.Brun@cern.ch)
Date: Wed Oct 25 2000 - 12:28:32 MEST


Hi Daniel,

Your link sequence is not correct. 
We provide $ROOTSYS/bin/root-config in the standard Root distribution.
See for example in $ROOTSYS/test/Makefile how this is used.

This small script generates automatically the correct link procedure
in a system/compiler independent way. We always recommend to use this
script instead of an adhoc list of libraries. If we add/remove a library
in the next versions, this procedure will always work.
type root-config 
to see the list of options.

Rene Brun

Daniel Cussol wrote:
> 
> Hello everybody,
>  I am a newcomer in Root system. I am running the 2.25 version on a unix
> Alpha OSF1 using cxx. I tried to implement in Root a personal
> Class THEvsN dervied from TH2F.
> 
> //
> // Declaration des spectres E*/N vs N
> //
> 
> #include "Rtypes.h"
> #include "TH2.h"
> 
> class THEvsN:public TH2F
>         {
>         public:
>                 int     np,nc;
>                 float   Edisp;
> 
>         THEvsN(void);
>         THEvsN(TH2F *spec);
>         ~THEvsN(void);
> 
>         virtual void Draw(Option_t *option);
> 
>         ClassDef(THEvsN,1)
> 
> 
>         };
> =============================================================================
> //
> // Implementation des spectres E*/N vs N
> //
> #include <iostream.h>
> #include <stdio.h>
> #include <math.h>
> #include "TGraph.h"
> #include "THEvsN.h"
> 
> ClassImp(THEvsN)
> 
> THEvsN::THEvsN(void):TH2F()
>         {
>         np=0;
>         nc=0;
>         Edisp=0.;
>         }
> 
> THEvsN::THEvsN(TH2F *spec):TH2F(*spec)
>         {
>         char    titre[80];
>         sprintf(titre,"%s (THEvsN)\0",spec->GetName());
>         SetName(titre);
>         cout << "L'histogramme "<< this->GetName() << " de type THEvsN a ete cree." << endl;
>         }
> 
> THEvsN::~THEvsN(void)
>         {
>         }
> 
> void THEvsN::Draw(Option_t *option)
>         {
>         TGraph  *graph=new TGraph();
>         int     i;
>         int     nbe=100;
>         float epl[100];
>         float am[100];
>         float em[100];
>         float esa[100];
>         float eplb[100];
>         float rm[100];
>         float qm[100];
> 
>         FILE *fstatic=fopen("/home/grpun/cussol/n_corps/statique/statique_1_100.data","r");
> 
>         printf("fstatic=%d\n",fstatic);
> 
>         for (i=0;i<nbe;i++)
>                 {
>                 fscanf(fstatic,"%f %f %f %f %f %f\n",&am[i],&rm[i],&esa[i],&eplb[i],&rm[i],&qm[i]);
>                 }
>         fclose(fstatic);
> 
>         cout << nbe << " valeurs dans les tableaux..." << endl;
>         TH2F::Draw(option);
>         for (i=0;i<nbe;i++)
>                 epl[i]=-esa[i];
>         graph->SetLineColor(4);
>         graph->DrawGraph(nbe,am,epl,"l");
>         for (i=0;i<nbe;i++)
>                 epl[i]=-eplb[i];
>         graph->SetLineColor(6);
>         graph->DrawGraph(nbe,am,epl,"l");
>         }
> 
> 
> I have read the .html pages related to
> that subject. So I use the following Makefile:
> #---------------------------------------------------
> CXXFLAGS      = -g  -z -I${ROOTSYS}/include
> LDFLAGS       = -g  -z -shared -L${ROOTSYS}/lib/ -rpath ${ROOTSYS}/lib/
> LD            = ld
> 
> COMPIL        = cxx
> 
> LIBS          = ${ROOTSYS}/lib/*.so -lXpm -lX11 -lm -lcxx -lc
> 
> HDRS          = THEvsN.h
> 
> SRCS          = main_root.C THEvsN.C mydict.C
> 
> OBJS          = main_root.o THEvsN.o mydict.o
> 
> PROGRAM       = monroot
> 
> all:            ${PROGRAM}
> 
> ${PROGRAM}:     ${OBJS}
>                 @echo "Linking ${PROGRAM} ..."
>                 @${LD} ${LDFLAGS} ${OBJS} ${LIBS} -o ${PROGRAM}
>                 @chmod +x ${PROGRAM}
>                 @echo "done"
> 
> clean:;         @rm -f ${OBJS} core
> 
> ###
> THEvsN.o: THEvsN.h THEvsN.C
>                 @echo "Compilation de THEvsN.C"
>                 @$(COMPIL) -c ${CXXFLAGS} THEvsN.C
> 
> main_root.o: THEvsN.h main_root.C
>                 @echo "Compilation de main_root.C"
>                 @$(COMPIL) -c ${CXXFLAGS} main_root.C
> 
> mydict.o:  mydict.C
>                 @echo "Compilation de mydict.C"
>                 @$(COMPIL) -c ${CXXFLAGS} mydict.C
> 
> mydict.C: THEvsN.h
>                 @echo "Generating dictionary ..."
>                 @rootcint mydict.C -c THEvsN.h
> #---------------------------------------------------
> 
> The compilation and the linking are OK. But when I run
> my executable file "monroot", the following error occurs:
> 
> 346626:monroot: /sbin/loader: Error: Unresolved symbol in
> /usr/shlib//libc.so: _end
> 346626:monroot: /sbin/loader: Fatal Error: this executable has
> unresolvable symbols
> 
> I suspect an error in load flags definitions or in the copiler flag
> definitions, but I can not find it. Did somebody had this problem? Could
> somebody help me?
> 
>  Thanks in advance
>  Friendly
> 
> Daniel CUSSOL
> 
> LPC Caen
> Boulevard du Marechal Juin
> 14050 CAEN CEDEX
> 
> e-mail : cussol@in2p3.fr
> Tel    : +33-(0)2-31-45-29-73
> FAX    : +33-(0)2-31-45-25-49



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