Re: [ROOT] Help compiling a class

From: Christian Holm Christensen (cholm@hehi03.nbi.dk)
Date: Tue Sep 19 2000 - 22:42:52 MEST


Hi Ray, Victor, and other ROOT'ers

On Tue, 19 Sep 2000 13:11:05 -0400
Victor Perevoztchikov <perev@bnl.gov> wrote
concerning ": Re: [ROOT] Help compiling a class":
> Hi Ray,
> 
> > dlopen error: /direct/u0b/rfliller/data/ROOT/./testclass.so: undefined
> > symbol: ShowMembers__9TestclassR16TMemberInspectorPc
> 
> unfortunatelly for Linux and Solaris such message is usually wrong.
> This means only that you do not have implemenatation for some method,
> not ShowMembers. Very often it is destructor declared but not implemented.

Err, that's not right. This error has nothing NOTHING to do with
Linux or Solaris, but is rather a mistake on Ray's part (though he'd
be excused, since this is one point where no doc is really clear). 

Victor, this has nothing to do with the previous discussion on this
list on how to find symbols in the ROOT libraries. Ray would have
faired equally bad on Windoze or HP!

Here's what happens: 
When you process a header file with rootcint with out the explicit use
of a LinkDef.h file, rootcint assumes that the class you want to
create the dictonary for is named like the header file (with out the
.h  part in the end of course). So in Ray's case, with header file name
"testclass.h", this is what causes the problem and the error message: 

  Generating dictionary testclassDict...
  Note: link requested for unknown class testclass FILE:G__autoLinkDef.h 
  LINE:7
  Note: operator new() masked 1c
  Note: operator delete() masked 1c

since there is no class in "testclass.h" named 'testclass', but rather
'Testclass'. Hence, the methods of Testclass that rootcint is supposed
to create the implementation for (that is 'Streamer', 'ShowMembers',
etc.) isn't created at all, but is declared in the header file via
ClassDef(Testclass,0). 

So after creating the shared library (which doens't need all symbols
to be resolved at link time), the symbol
ShowMembers__9TestclassR16TMemberInspectorPc (or
Testclass::ShowMembers(TMemberInspector &R__insp, char *R__parent))
is left undefined in "testclass.so", and when you try to load
"testclass.so" it fails, 'cause ROOT wants to resolve the symbol! 

So, in short, the solution is to rename your file from "testclass.h"
to "Testclass.h", and everything should work smoothly. In fact, I
recommend you rename "testclass.cxx" to "Testclass.cxx" as well, for
consitency, etc.. Hence the commads to make the lib should be (on
Linux, that is):
  
  prompt% rootcint -f TestclassDict.cxx -c Testclass.h 
  prompt% g++ -c `root-config --cflags` Testclass.cxx -o Testclass.o 
  prompt% g++ -c `root-config --cflags` TestclassDict.cxx -o TestclassDict.o 
  prompt% g++ -shared -Wl,-soname,Testclass.so Testclass*.o -o Testclass.so
       

Apart from that Ray, you have an error in your header file: 

    ClassDef(Testclass,1);
                         ^                         |

There MUST NOT be any semi-colon (;) after the ClassDef macro! It
probably f**ks up your indention style in Emacs (!) but that's life,
I'm afraid. With the semi-colon, the needed methods is not created,
much like if your file was named "testclass.h"! This is what is the
cause of the errors: 

  Generating dictionary testclassDict...
  Note: operator new() masked 1c
  Note: operator delete() masked 1c
  Class Data: Streamer() not declared
  Class Data: ShowMembers() not declared


> Try:
> 
> nm testclass.so | grep Testclass | grep ' U '

it should be (on Linux using GNU binutils):

  prompt% nm -C Testclass.so | grep "        U "

the "-C" is to 'demangle' the symbols,

> and you will see all unsatisfied methods. Check them.

and be amazed at the number of undefined symbols!
 
> On HP diagnostic always correct

>From what I've said above, it should be clear it's not a OS problem. 

Hope that clears up a few things, 

Christian  -----------------------------------------------------------
Holm Christensen                             Phone:  (+45) 35 35 96 91 
  Sankt Hansgade 23, 1. th.                  Office: (+45) 353  25 305 
  DK-2200 Copenhagen N                       Web:    www.nbi.dk/~cholm    
  Denmark                                    Email:       cholm@nbi.dk



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