rootcint -f cint.C -c read.h rLinkDef.h
g++ -fno-rtti -fno-exceptions -fPIC -I$ROOTSYS/include -c cint.C read.C
g++ -g -Wl,-soname,myclass.so -shared cint.o read.o -o myclass.so
file read.h
===========
void read(); // one line only
file rLinkDef.h
===============
#ifdef __CINT__
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C function read;
#endif
file read.C
===========
//this is the read program which i put into a
//shared lib.
#include <TFile.h>
#include <TCanvas.h>
#include <iostream>
void read()
{
TFile * tf = new TFile ("bla.root","read");
cout << "oops"<<endl;
TCanvas * c1 = (TCanvas *) tf->Get("canvas"); // segfault here.
cout << "worked."<<endl;
c1->Draw();
}
macro bla.C creating the file with a canvas
============================================
//this is a macro which produces a root file.
//i call it interactively, in naked root.
void bla1()
{
h=new TH2F("h","", 1,0,10,1,0,10);
Float_t x[5]={ 1,9,2,8,3 };
Float_t y[5]={ 1,1,2,2,7 };
TPolyMarker pm(5,x,y);
pm->SetMarkerStyle(22);
h->Draw();
pm->Draw();
tf = new TFile ("bla.root","recreate");
c1->Write("canvas");
//at this point you must see an empty canvas (pm destructor has been
called)
}
run a Root session executing the above macro bla.C
run the first script at the top running rootcint, g++ and making
the shared lib myclass.so
run the following Root session
root
Root > gSystem->Load("myclass");
Root > read(); //this should work. it will display teh original canvas
Rene Brun
J. Rieling wrote:
>
> -----BEGIN PGP SIGNED MESSAGE-----
>
> hi Rene,
>
> you wrote:
>
> > I suspect a missing include or like in your batch program.
> > Could you send me (not the list) a copy of your small program.
>
> certainly.
> i boiled the problem down to a few lines.
>
> please find in att.1 the following 2 files:
> 1.) a macro mkrootfile.C
> which creates the problematic(?) root file, and
>
> 2.) a C++-prg. read.C which i translate into a
> shared lib & use for reading.
>
> att.2 contains a dump of the root session where root
> refuses to execute read.C
>
> att.3 contains a dump of the root session where root
> performs the identical commands w/o problems.
>
> hope you can reproduce the problem :-)
> see you & thanks for your efforts,
>
> j"org.
>
> __________________________________________________________________________
> dr. j. rieling / daimlerChrysler aerospace, orbital systems & operations
> fon +49 421 5395643 fax +49 421 5395127 joerg.rieling@ri.dasa.de
>
> -----BEGIN PGP SIGNATURE-----
> Version: PGPfreeware 5.0i for non-commercial use
> Charset: noconv
>
> iQCVAwUBN0GQ7zj2v2S/jY1FAQFRjAQAhurPF91kq0aK+lv+zCzewBAdQMtCMU8C
> ckMSz+kcdnpGdmapjMq5b6GEpIfvMtmdv+cP8lNVE/n1nJy7Ub9cUixGgNzrqNc3
> tX/6AM4ZaFJjRi13GGZEGNQhGlDSJImQPdZNsIaYD/8z1SZ3Iieg2HUxE4W2REgv
> xi0/I650ZMc=
> =1F34
> -----END PGP SIGNATURE-----
>
> ------------------------------------------------------------------------
>
> Name: bla1
> bla1 Type: Plain Text (TEXT/PLAIN)
> Encoding: BASE64
>
> Name: bla2
> bla2 Type: Plain Text (TEXT/PLAIN)
> Encoding: BASE64
>
> Name: bla3
> bla3 Type: Plain Text (TEXT/PLAIN)
> Encoding: BASE64