Undefined reference to `vtable for myClass' with scramv1


Using 4.03.04a/slc3_ia32_gcc323 and scramv1.

I am trying to define my own ROOT class for creating a root-tuple. Compilation works
fine, but upon linking I’m getting the following errors:

undefined reference to vtable for myClass' undefined reference totypeinfo for myClass’
collect2: ld returned 1 exit status

A google search suggests that I am doing something wrong with the dictionary generation
of my class. Is this done via the “#pragma link etc” statements, or is there something that I need to add to my Buildfile?

(I hope the above is enough information)



Forgot to mention that I found this answer (to a similar problem) by Philippe, but I don’t really
understand what the solution is:
root.cern.ch/cgi-bin/print_hit_b … /1627.html
Could somebody please make it more explicit?

If you’ve generated correctly the dictionary it can also be caused by not having all virtual methods implemented.

Cheers, Fons.

Dear Fons,

I’m afraid that this is exactly my problem: I do not know how to generate the dictionary when using scramv1. To illustrate why I do not think this is a problem with my code, when I move the implementation of some of my class methods from the header file to a new, source file, I get the following linking errors:

undefined reference to myClass::Class()' undefined reference toROOT::GenerateInitInstance(myClass const*)'
undefined reference to myClass::ShowMembers(TMemberInspector&, char*)' undefined reference tomyClass::Streamer(TBuffer&)'
collect2: ld returned 1 exit status

The “myClass” class compiles, links and runs fine if I put it in a ROOT macro and run with “root my_macro.C+”. Doesn’t this prove that the problem lies in the way the dictionary needs to be defined for scramv1?


Ok, here’s the solution to my problem:

(1) I had to put my “LinkDef” file in the src directory:

#include "long_path_name/myClass.h"

#ifdef __CINT__

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;

#pragma extra_include "long_path_name/myClass.h"

#pragma link C++ class myClass;

#endif // __CINT__

(2) After that, trying to (re)compile/(re)link gave me an error for a missing libCint.so library. So, I had to do


eval `scramv1 runtime -csh`
scramv1 b -r

which solved my problems. So, I guess (ignoring the fact that I was supposed to know step #1) this is more a scram(v1) question than a ROOT one…