Undefined reference to ... virtual table

Hi Root,
I am working with gcc 2.95.4 and ROOT 3.10/02 on Debian Linux.

I am writing a geant4 application involving some ROOT classes I made for myself and then compiled into a shared library (.so). Whenever I write a new class (for use as a Branch in a TTree) and try to link it in via the library, I get linking errors about “undefined references” to “virtual tables”. Here is an example:

Linking mulan …
/.autofs/home/asharp/work/mulan/tmp/Linux-g++/mulan/libmulan.a(TReadoutTilePair.o): In function TReadoutTilePair::TReadoutTilePair(void)': /home/asharp/work/mulan/src/TReadoutTilePair.cc:5: undefined reference toTReadoutTilePair virtual table’
/.autofs/home/asharp/work/mulan/tmp/Linux-g++/mulan/libmulan.a(TReadoutTilePair.o): In function __static_initialization_and_destruction_0': /home/asharp/work/mulan/src/TReadoutTilePair.cc:2: undefined reference toROOT::GenerateInitInstance(TReadoutTilePair const *)’
collect2: ld returned 1 exit status
make: *** [/.autofs/home/asharp/work/mulan/bin/Linux-g++/mulan] Error 1

I will attach a tar file so that you can reproduce the error. To me, it looks like the __static_initialization_and_destruction_0' andROOT::GenerateInitInstance(TReadoutTilePair const *)’ errors come from an incomplete build of the library with rootcint? Previously I wrote two different analysis classes, linked them into the library, and they work fine. Can you help me figure out what is wrong? Thanks!
-Andrea Sharp
source.tar (730 KB)


There are missing file to be able to recompile your code:

GNUmakefile:20: …/…/…/…/config/binmake.gmk: No such file or directory[/quote]

Anyway since you have a static library:
you might have to make sure that both the library AND the executable is linked against the dictionary .o file.


Hello Philippe,
Here is missing binmake.gmk.
What really confuses me is that the older classes in the library (like TReadoutWorld) work just fine inside the geant4 code. All the TReadout classes are compiled together into libTReadout.so, which indicates that at least something is working right since the other classes work. So I can’t figure out the error with this new class.
Andrea Sharp

The file doesn’t seem to attach well. Trying again.
source.tar (740 KB)


I do not have Geant4 installed! Hence your build is still failing (now with messages like:

[quote]binmake.gmk:8: …/…/…/…/config/architecture.gmk: No such file or directory
binmake.gmk:13: …/…/…/…/config/G4UI_USE.gmk: No such file or directory
binmake.gmk:14: …/…/…/…/config/G4VIS_USE.gmk: No such file or directory
binmake.gmk:15: …/…/…/…/config/interactivity.gmk: No such file or directory
binmake.gmk:16: …/…/…/…/config/analysis.gmk: No such file or directory
binmake.gmk:157: …/…/…/…/config/common.gmk: No such file or directory
mkdir: cannot create directory `//mulan’: Permission denied[/quote]

Anyway I tried the simple:

[quote]rootcint -f Dictionary.cpp -c -I…/include -I…/rootlibs TReadoutBranch.hh TReadoutWorld.hh TReadoutTarget.hh TReadoutTilePair.hh TReadoutSimple.hh LinkDef.h
g++ -I…/include -I…/rootlibs -Wall -shared -I$ROOTSYS/include -I. TReadoutBranch.cc TReadoutWorld.cc TReadoutTarget.cc TReadoutTilePair.cc TReadoutSimple.cc Dictionary.cpp -o lib/libTReadout.so root-config --libs[/quote]

And this did work fine. I suspect that you have a makefile type of problem where it is not (for some reason) picking up the right version of the compiled dictionary.

I recommend that you start fresh (i.e remove ALL libraries and ALL .o files and ALL dictionaries).


Thanks Philippe,
I’m still looking for the error. No wonder your compilation didn’t work since you don’t have G4 installed! :slight_smile:
The library could be loading improperly. I’ve been looking at the makefile but haven’t solved it yet. Thanks for your help!