gSystem->Load() undefined symbol error

I am trying to use classes generated by TFile::MakeProject in my macro. When I try to use ClassA in my macro (classA is defined in the generated library), I get undefined symbol error:

[lzer@68snzq1-wired ClassA_dbg]$ root -l libtest.C++
root [0] 
Processing libtest.C++...
Info in <TUnixSystem::ACLiC>: creating shared library /home/bloo/ClassA_dbg/./libtest_C.so
cling::DynamicLibraryManager::loadLibrary(): /home/bloo/ClassA_dbg/libtest_C.so: undefined symbol: _ZTI20ClassA
/lib/../lib64/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
/home/bloo/ClassA_dbg/libtest_C_ACLiC_dict.o: In function `int TTree::SetBranchAddress<ClassA>(char const*, ClassA*, TBranch**)':
libtest_C_ACLiC_dict.cxx:(.text._ZN5TTree16SetBranchAddressI20ClassAEEiPKcPT_PP7TBranch[_ZN5TTree16SetBranchAddressI20ClassAEEiPKcPT_PP7TBranch]+0x23): undefined reference to `typeinfo for ClassA'
libtest_C_ACLiC_dict.cxx:(.text._ZN5TTree16SetBranchAddressI20ClassAEEiPKcPT_PP7TBranch[_ZN5TTree16SetBranchAddressI20ClassAEEiPKcPT_PP7TBranch]+0x3f): undefined reference to `typeinfo for ClassA'
collect2: error: ld returned 1 exit status

this is a stripped down test macro which gives the above error:

#include "myLib/myLibProjectHeaders.h"
#include <TSystem.h>
#include <TChain.h>
#include <iostream>

void libtest()
{
gSystem->Load("myLib/myLib.so");
ClassA* Evt = nullptr;
TChain* mChain = new TChain("Tree1");
mChain->Add("testfile.root");
mChain->SetBranchAddress("BranchA",Evt);
std::cout<<"loaded"<<std::endl;
for(ULong64_t iev=0;iev<mChain->GetEntries();iev++)
{
	mChain->GetEntry(iev);
	if(iev%20==0)	std::cout<<iev<<std::endl;
}
std::cout<<"finni"<<std::endl;
}

Any ideas what i’m doing wrong here?
Thanks in advance.

ROOT Version: 6.16/00
Platform: CentOS 7
Compiler: gcc 7.3.0


With ROOT 6 this can be a bit tricky.
I guess the best idea (which should work with ROOT 5 and 6) is to create a simple local “rootlogon.C” file in your “current working directory”:

void rootlogon(void) { // rootlogon.C ...
  // std::cout << "... rootlogon.C ..." << std::endl;
  gSystem->Load("myLib/myLib.so");
} // ... rootlogon.C

and remove the “gSystem->Load(...);” statement from the “libtest.C”.

May be this helps:

Otto

Hey, so I tried this rootlogon in my wd and am still getting the undefined symbol error.

Try (see TSystem::Load for error codes):

void rootlogon(void) { // rootlogon.C ...
  // std::cout << "... rootlogon.C ..." << std::endl;
  int v = gSystem->Load("myLib/myLib.so");
  if (v != 0) std::cout << "Error loading myLib: " << v << std::endl;
} // ... rootlogon.C

Maybe relevant here: Rootcling ignores loading of library within macro

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.