Linking in and out of ROOT

Hello, I have a class that I would like to save to a TFile and so needs to inherit from TObject. I want to use the same class in a non-ROOT, pure c++ program compiled with g++. The code below runs fine when compiled in ROOT (.L RunData.C+) but when linking outside ROOT, it returns an “undefined reference to `vtable for RunData’” error.

My understanding is that this error has something to do with declaring a function but not implementing it? Any suggestions will be appreciated!

RunData.hh

#ifndef __RunData__                                                                                                  
#define __RunData__                                                                                                                                        
#include "TObject.h"                                                                                                    
class RunData : public TObject {                                                                                     
 public:                                                                                                                
  RunData();                                                                                                         
  ClassDef(RunData, 1);                 // Test Class                                                                
 private:                                                                                                               
  Double_t polarization_;                                                                                               
  Double_t alignment_;                                                                                                  
};                                                                                                                      

RunData.cc

#include <iostream>                                                                                                                                             
#include "RunData.hh"                                                                                                
ClassImp(RunData)                                                                                                    
using namespace std;                                                                                                    
                                                                                                                        
RunData::RunData() {                                                                                              
  cout << "I am here." << endl;                                                                                         
  polarization_ = 0.94;                                                                                                 
  alignment_ = 0.234;                                                                                                   
}                               

So again, this runs fine within ROOT but fails outside ROOT. Any ideas on how to make this work?

Hi,
I’m not sure what you understand by pure “non-root” program. You can’t use “pure non-root” program because you use TObject class that is part of ROOT. Of course you can probably avoid this by using some tricks with #ifndef’s. But if you just want executable file that only require root libraries but can be launched by ./runprogram instead of running CINT by root command and .x myClass.C you should build dictionary, you can read about them here http://root.cern.ch/root/CintGenerator.html.
Cheers.