Dear Rooters,
I am suffering troubles when constructing my class
with ifstream for ROOT I/O.
The shared library, libMyClass.so is successfully construced, but
it can't be linked to other objects and can't be loaded in ROOT(CINT).
If the line, 'std::ifstream fi; //! excluded'
is commented out (at MyClass.h), all works fine.
Is there any idea to solve the problem?
/////////////////////////////////////////////////
The error outputs are...
root [1] gSystem->Load("libMyClass")
dlopen error: /afs/cern.ch/user/n/nanjo/MyClassStreamer/./libMyClass.so: undefined symbol: _ZNSt8ios_baseC2ERKS_
Load Error: Failed to load Dynamic link library /afs/cern.ch/user/n/nanjo/MyClassStreamer/./libMyClass.so
*** Interpreter error recovered ***
or
g++ `root-config --cflags` -c MyClass.C
rootcint -f MyClassDict.C -c MyClass.h MyClassLinkDef.h
g++ `root-config --cflags` -c MyClassDict.C
g++ -shared MyClass.o MyClassDict.o -o libMyClass.so
// Succeed
g++ `root-config --cflags` -c write.C
// OK
g++ write.o libMyClass.so `root-config --libs` -o write
// Fail
libMyClass.so: undefined reference to `std::ios_base::ios_base[not-in-charge](std::ios_base const&)'
collect2: ld returned 1 exit status
/////////////////////////////////////////////////
My environment is...
uname -a
Red Hat Linux release 7.3 (Valhalla)
Linux lxplus072 2.4.20-28.7.cernsmp #1 SMP Fri Jan 9 12:37:16 CET 2004 i686 unknown.
g++ -v
Reading specs from /usr/local/gcc-alt-3.2/lib/gcc-lib/i686-pc-linux-gnu/3.2/specs
Configured with: ./configure --prefix=/usr/local/gcc-alt-3.2 --enable-shared
Thread model: posix
gcc version 3.2
The ROOT is on afs at CERN.
*******************************************
* *
* W E L C O M E to R O O T *
* *
* Version 3.10/02 16 December 2003 *
* *
* You are welcome to visit our Web site *
* http://root.cern.ch *
* *
*******************************************
///////////////////////////////////////////////////
My codes are as follows.
///////////////////////////////////////////////////
//
// MyClass.h
//
#ifndef MyClass_HH
#define MyClass_HH
#include <fstream>
#include "TObject.h"
class MyClass: public TObject
{
public:
MyClass();
~MyClass();
void Set(int s);
public:
int size;
std::ifstream fi; //! excluded
ClassDef(MyClass,1) //MyClass
};
#endif
///////////////////////////////////////////////////
///////////////////////////////////////////////////
///////////////////////////////////////////////////
//
// MyClass.C
//
#include "MyClass.h"
#if !defined(__CINT__)
ClassImp(MyClass);
#endif
MyClass::MyClass() {
size=0;
}
MyClass::~MyClass() {
;
}
void MyClass::Set(int s) {
size=s;
}
///////////////////////////////////////////////////
//
// hadDataLinkDef.h
//
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class MyClass;
#endif
///////////////////////////////////////////////////
///////////////////////////////////////////////////
///////////////////////////////////////////////////
//
// write.C
//
#include "TApplication.h"
#include "TFile.h"
#include "TTree.h"
#include "MyClass.h"
int main(int argc,char** argv)
{
TApplication app("app", &argc, argv);
TFile *tf = new TFile("tmp.root","RECREATE");
TTree *tree = new TTree("tree","tmp");
MyClass *data = new MyClass();
tree->Branch("data","MyClass",&data);
for (int i=0;i<5;++i) {
data->Set(i+1);
tree->Fill();
}
tf->Write();
delete data;
return 0;
}
///////////////////////////////////////////////////
///////////////////////////////////////////////////
///////////////////////////////////////////////////
//
// compile script
//
rm *.o
rm *.so
rm MyClassDict.C
g++ `root-config --cflags` -c MyClass.C
rootcint -f MyClassDict.C -c MyClass.h MyClassLinkDef.h
g++ `root-config --cflags` -c MyClassDict.C
g++ -shared MyClass.o MyClassDict.o -o libMyClass.so
g++ `root-config --cflags` -c write.C
g++ write.o libMyClass.so `root-config --libs` -o write
///////////////////////////////////////////////////
This archive was generated by hypermail 2b29 : Sun Jan 02 2005 - 05:50:05 MET