ROOT on Ubuntu: "no dictionary for class..."

I have installed ROOT v5.30.03 on Ubuntu 11.10. I am having trouble reading a TFile with compiled code; interactively it works fine. I’ve put a small example below that illustrates the problem.

To generate the test file:

{
  TFile *f = new TFile("test.root", "recreate");
  TH1F* h = new TH1F("h", "h", 100, 1, 100);
  for (int i = 1; i < 101; ++i) h->Fill(i);
  h->Write();
  f->Close();
}

To read this file I use “tiny.C”:

#include "TROOT.h"
#include "TApplication.h"
#include "TSystem.h"
#include "TFile.h"
#include "TH1.h"
#include "TH1F.h"
#include "TAxis.h"

int main(int argc, char *argv[])
{
  TApplication app("app", &argc, argv);
  TFile *f = new TFile("test.root", "read");
  return 0;
}

Which is then compiled using:

g++ `root-config --cflags` -c tiny.C -o tiny.o
g++ tiny.o `root-config --libs` -o tiny

When I run “tiny”, I get:

dlopen error: /usr/local/src/root-5.30.03/lib/libHist.so: undefined symbol: _ZTI14TVirtualFitter
Load Error: Failed to load Dynamic link library /usr/local/src/root-5.30.03/lib/libHist.so
Error in <TCint::AutoLoad>: failure loading library libHist.so for class TH1F
Warning in <TClass::TClass>: no dictionary for class TH1F is available
Warning in <TClass::TClass>: no dictionary for class TH1 is available
Warning in <TClass::TClass>: no dictionary for class TAxis is available

I have searched the forum and I am aware that this problem has occurred before, but I have tried all of the suggestions (e.g. adding TApplication) and none of them seem to work. The strange thing is this procedure works fine on SLC5 with ROOT v5.30.00. Where might I be going wrong? I have the same trouble on Ubuntu with version 5.28.00g. Any hints would be greatly appreciated.

Tryg++ `root-config --ldflags` -o tiny tiny.o `root-config --libs`
Make sure you didexport LD_LIBRARY_PATH="`root-config --libdir`:${LD_LIBRARY_PATH}"

Thanks, but I get the same problem using this method.

LD_LIBRARY_PATH is already equal to root-config --libdir; I am running thisroot.sh when I log in.

I found this thread: [url]Strange behavior reading TFile in Windows that mentioned a similar problem. It turns out that if I load a “dummy” histogram before opening the file, everything works fine:

#include "TROOT.h"
#include "TSystem.h"
#include "TFile.h"
#include "TH1.h"
#include "TH1F.h"
#include "TAxis.h"

int main(int argc, char *argv[])
{                                                               
  TH1F* dummy = new TH1F("dummy", "dummy", 10, 0, 1);
  TFile *f = new TFile("test.root", "read");
  return 0;
}

However, manually loading libHist and/or a TApplication does not work as far as I can see.

Edit:
It looks like I need I need to load a dummy TH1F regardless of the contents of the file. For example, a TH1F is required even if the file just contains a TTree. If I don’t do that, but instead create a dummy TTree, I get the following error on compilation:

/usr/local/src/root-5.30.03/lib/libNet.so: undefined reference to `gRandom'
A bit odd…

Hi,

ROOT v5.30.03 is not supported on Ubuntu 11.10 (due to Ubuntu’s change of linking semantic …)

To work around the problem you need to find the ‘right’ combination of explicitly listing the libraries. A guess would be g++ `root-config --ldflags` -o tiny tiny.o `root-config --libs` -Wl,--no-as-needed -lHist -lCore -lMathCore

Cheers,
Philippe.