Undefined reference to `HSG1Selector::Class()'

I justed googled for this problem but didn’t find a solution. So I compile my code with a makefile:

# Name of executable (in util/ folder) and targets (in src/ folder)i
MAIN        = run_example
TARGETS     = HSG1Selector example

CC          = g++
CXXFLAGS    = `root-config --cflags` -Wall -Wl,--no-as-needed
LDFLAGS     = `root-config --ldflags`
LDLIBS      = `root-config --libs` -L$(ROOTSYS)/lib -lEG -lTreePlayer -lCintex
INCLUDES    = -Iinclude
VPATH       = Root util
OBJDIR      = obj
SRCDIR      = Root
EXEDIR      = util

ALL     = $(MAIN) $(TARGETS)
SRCS    = $(patsubst %,$(EXEDIR)/%.cxx,$(MAIN)) $(patsubst %,$(SRCDIR)/%.cxx,$(TARGETS)) 
OBJS    = $(patsubst %,$(OBJDIR)/%.o,$(ALL)) 

#############################################################################
# The following part of the makefile is generic
#############################################################################
.PHONY: depend clean

#print:
#   @echo $(SRCS)

all:	$(MAIN)
	@echo Program $(MAIN) has been compiled.
    
$(MAIN): $(OBJS) 
	$(CC) $(CXXFLAGS) $(INCLUDES) -o $(MAIN) $(OBJS) $(LDFLAGS) $(LDLIBS)

$(OBJDIR)/%.o: %.cxx
	$(CC) $(CXXFLAGS) -c $< $(INCLUDES) -o $@

clean:
	rm -f $(OBJS) $(MAIN)

This is my automatically generated class. I will just post the begin of all files:

[code] //////////////////////////////////////////////////////////
// This class has been automatically generated on
// Mon Jul 28 10:27:07 2014 by ROOT version 5.34/19
// from TTree truth/truth
// found on file: /global/zgecse/mc12_14TeV.189772.MadGraphPythia8_AU2CTEQ6L1_gg_hh125_bbyy_lambda01.merge.NTUP_TRUTH.e2944_p1614_tid01484633_00/NTUP_TRUTH.01484633._000021.root.1
//////////////////////////////////////////////////////////

#ifndef HSG1Selector_h
#define HSG1Selector_h

#include <TROOT.h>
#include <TChain.h>
#include <TFile.h>
#include <TSelector.h>

// Header file for the classes stored in the TTree if any.
#include

using namespace std;

// Fixed size dimensions of array or collections stored in the TTree if any.

class HSG1Selector : public TSelector {
public :
TTree *fChain; //!pointer to the analyzed TTree or TChain[/code]

This is example.h

[code]#ifndef example_h
#define example_h

#include “HSG1Selector.h”

class example : public HSG1Selector {

public:

  	void InitSelector(TString input, Long64_t numberEvtInChain);
   
protected:
virtual void Begin(TTree * /*tree*/);
virtual void	SlaveBegin(TTree * /*tree*/);
virtual Bool_t	Process(Long64_t entry);
virtual void	SlaveTerminate();
virtual void	Terminate();[/code]

Now this is the HSG1Selector.cxx:

[code]#define HSG1Selector_cxx
// The class definition in HSG1Selector.h has been generated automatically
// by the ROOT utility TTree::MakeSelector(). This class is derived
// from the ROOT class TSelector. For more information on the TSelector
// framework see $ROOTSYS/README/README.SELECTOR or the ROOT User Manual.

// The following methods are defined in this file:
// Begin(): called every time a loop on the tree starts,
// a convenient place to create your histograms.
// SlaveBegin(): called after Begin(), when on PROOF called only on the
// slave servers.
// Process(): called for each event, in this function you decide what
// to read and fill your histograms.
// SlaveTerminate: called at the end of the loop on the tree, when on PROOF
// called only on the slave servers.
// Terminate(): called at the end of the loop on the tree,
// a convenient place to draw/fit your histograms.
//
// To use this file, try the following session on your Tree T:
//
// Root > T->Process(“HSG1Selector.C”)
// Root > T->Process(“HSG1Selector.C”,“some options”)
// Root > T->Process(“HSG1Selector.C+”)
//

#include “HSG1Selector.h”
#include <TH2.h>
#include <TStyle.h>

void HSG1Selector::Begin(TTree * /tree/)
{
// The Begin() function is called at the start of the query.
// When running with PROOF Begin() is only called on the client.
// The tree argument is deprecated (on PROOF 0 is passed).

TString option = GetOption();

}[/code]

This is example.cxx

[code]#include “example.h”
//#include “HSG1Selector.h”
#include <TH2.h>
#include <TStyle.h>
#include
#include “TH1.h”
#include “TCanvas.h”

using namespace std;

TH1F *fHisto;

void example::InitSelector(TString input, Long64_t numberEvtInChain){

m_inputFile = input;
if(m_inputFile.IsNull()) Fatal("example::InitSelector","No input text.");

m_totChainedEvt = numberEvtInChain;
if(m_totChainedEvt == 0 ) Fatal("example::InitSelector","No event in TChain?");

}

void example::Begin(TTree * /tree/)
{
// The Begin() function is called at the start of the query.
// When running with PROOF Begin() is only called on the client.
// The tree argument is deprecated (on PROOF 0 is passed).

//std::cout<< jet_AntiKt4TruthJets_n.size() <<endl;

}[/code]

And this is the runner file

[code]#include “example.h”
#include <TROOT.h>
#include <Cintex/Cintex.h>
#include <TChain.h>
#include
#include
#include
#include

using namespace std;

int main(int argc, char* argv[]){

//ROOT::Cintex::Cintex::Enable();

std::string pgmName = "run_example";

if(argc!=2){
	std::cout<<"Wrong number of arguments!"<<std::endl;
	std::cout<<"Usage: ./util/"<< pgmName.c_str() <<" data/inputFile\n"<<std::endl;
	std::cout<<"Program terminated."<<std::endl;
	return 0;
}	

std::cout<<"_________________________________________________\n"<< std::endl;

std::cout<<"    Starting "<< pgmName.c_str()    << std::endl;
std::cout<<"_________________________________________________\n"<< std::endl;

ROOT::Cintex::Cintex::Enable();
/*
//----------------------------------------
// Building list of files (split by “,”)
//----------------------------------------
// File separator of %IN variable of prun is ","
std::string argStr = argv[1];
std::vectorstd::string fileList;
for (size_t i=0,n; i <= argStr.length(); i=n+1){
n = argStr.find_first_of(’,’,i);
if (n == std::string::npos)
n = argStr.length();
std::string tmp = argStr.substr(i,n-i);
fileList.push_back(tmp);
c }

//----------------------------------------
// Chaining files
//----------------------------------------
//TChain fChain("susy");
TChain* chain = new TChain("susy");
for (unsigned int iFile=0; iFile<fileList.size(); ++iFile){
	std::cout << "Chaining " << fileList[iFile].c_str() << std::endl;
	chain->Add(fileList[iFile].c_str());
	std::cout << "\t=> done chaining " << fileList[iFile].c_str() << std::endl;
}

std::cout<<"\nTotal number of events in the sample: "<<chain->GetEntries()<<std::endl;

HiggsbbSUSYSelector * mySelector = new HiggsbbSUSYSelector();
chain->Process(mySelector);

*/

//----------------------------------------
// Chaining files from input file
//----------------------------------------
TString input = argv[1];
ifstream inputFile(input);
if(!inputFile){
	printf("Can't find input text file %s. Exiting program.\n", input.Data());
	exit(-1);
}
TString D3PDinputDir = getenv("D3PDINPUTDIR"); printf("dir = %s\n",D3PDinputDir.Data());
TString dataset;

TChain* chain = new TChain("truth");
while(inputFile >> dataset){
	printf("Chaining file %s\n", dataset.Data());
	chain->Add(D3PDinputDir+dataset);
	printf("======> Done.\n");
}

printf("Total number of events in the sample: %llu\n", chain->GetEntries());

//----------------------------------------
// Creating TSelector
//----------------------------------------     
example * mySelector = new example();
mySelector->InitSelector(input, chain->GetEntries());
chain->Process(mySelector);

std::cout<<"_________________________________________________\n"<< std::endl;

std::cout << "    End of "<< pgmName.c_str()    << std::endl;
std::cout<<"_________________________________________________\n"<< std::endl;

return 0;

}
[/code]

The error of the compiler is the following:

> make -f cmt/Makefile g++ `root-config --cflags` -Wall -Wl,--no-as-needed -c util/run_example.cxx -Iinclude -o obj/run_example.o g++ `root-config --cflags` -Wall -Wl,--no-as-needed -c Root/HSG1Selector.cxx -Iinclude -o obj/HSG1Selector.o g++ `root-config --cflags` -Wall -Wl,--no-as-needed -c Root/example.cxx -Iinclude -o obj/example.o g++ `root-config --cflags` -Wall -Wl,--no-as-needed -Iinclude -o run_example obj/run_example.o obj/HSG1Selector.o obj/example.o `root-config --ldflags` `root-config --libs` -L/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase/x86_64/root/5.34.19-x86_64-slc6-gcc4.7/lib -lEG -lTreePlayer -lCintex obj/HSG1Selector.o: In function `HSG1Selector::IsA() const': HSG1Selector.cxx:(.text._ZNK12HSG1Selector3IsAEv[_ZNK12HSG1Selector3IsAEv]+0xd): undefined reference to `HSG1Selector::Class()' obj/HSG1Selector.o:(.rodata._ZTV12HSG1Selector[_ZTV12HSG1Selector]+0x1d0): undefined reference to `HSG1Selector::ShowMembers(TMemberInspector&)' obj/HSG1Selector.o:(.rodata._ZTV12HSG1Selector[_ZTV12HSG1Selector]+0x1d8): undefined reference to `HSG1Selector::Streamer(TBuffer&)' obj/example.o:(.rodata._ZTV7example[_ZTV7example]+0x1d0): undefined reference to `HSG1Selector::ShowMembers(TMemberInspector&)' obj/example.o:(.rodata._ZTV7example[_ZTV7example]+0x1d8): undefined reference to `HSG1Selector::Streamer(TBuffer&)'

Does anybody knows the solution of this mistake? Thank you very very much!

Hi,

For the record, the solution has been given in the Jira issue #ROOT-6533 you opened:

[quote=“Philippe Canal”]Hi,
You need to generate and compile a dictionary for the class HSG1Selector.
See for example root.cern.ch/drupal/content/inte … s-rootcint
Cheers,
Philippe.[/quote]Cheers, Bertrand.