Re: Adding my own class to ROOT

Rene Brun (Rene.Brun@cern.ch)
Fri, 04 Dec 1998 08:49:40 +0100


Glen R. Salo wrote:
>
> I am having problems adding my own class to ROOT. My sample code compiles,
> but fails on the link. The error message I get is:
>
> /tmp/cca018401.o: In function `IO::ImplFileLine(void)':
> /home/gsalo/root/io.C:20: undefined reference to
> `IO::ShowMembers(TMemberInspector &, char *)'
> /tmp/cca018401.o: In function `IO::IO(void)':
> /home/gsalo/root/io.C:22: undefined reference to
> `IO::Streamer(TBuffer &)'
> collect2: ld returned 1 exit status
>
> The test code along with the compiler commands are given below. I am running
> version 2.20 under Redhat 5.2. Any idea what I'm doing wrong?
>
> Thanks for your help.
>
> Glen
>
> #include "TFile.h"
> #include "TObject.h"
> #include <iostream>
>
> class myclass : public TObject {
>
> private:
> Int_t a;
>
> public:
> myclass();
> ~myclass();
> void seta(Int_t aa);
> Int_t geta();
>
> ClassDef(myclass,1)
>
> };
>
> ClassImp(myclass)
>
> myclass::myclass() { }
> myclass::~myclass() { }
> void myclass::seta(Int_t aa) { a = aa; }
> Int_t myclass::geta() { return a; }
>
> int main () {
>
> myclass var;
>
> var.seta(30);
> cout << var.geta() << endl;
>
> TFile file = TFile("test.dat","RECREATE");
> var.AppendDirectory();
>
> return 0;
>
> }
>
> g++ -o io -g -Wall -fno-rtti -fno-exceptions -fPIC io.C
> -I/usr/local/root/include -L/usr/local/root/lib -L/usr/X11R6/lib -lNew -lBase
> -lCint -lClib -lCont -lFunc -lGraf -lGraf3d -lHist -lHtml -lMatrix -lMeta
> -lMinuit -lNet -lPostscript -lProof -lTree -lUnix -lZip -lGpad -lGui -lGX11
> -lX3d -lXpm -lX11 -lm -ldl -rdynamic
>
> /tmp/cca018471.o: In function `myclass::ImplFileLine(void)':
> /home/gsalo/root/io.C:20: undefined reference to
> `myclass::ShowMembers(TMemberInspector &, char *)'
> /tmp/cca018471.o: In function `myclass::myclass(void)':
> /home/gsalo/root/io.C:22: undefined reference to `myclass::Streamer(TBuffer &)'
> collect2: ld returned 1 exit status

Glen,
You forgot to run rootcint to generate the dictionary for your class.
See example in $ROOTSYS/test/Makefile when generating the program Event
For more info about the dictionary, see URL:
http://root.cern.ch/root/Dictionary.html

Rene Brun