Adding own class to root


I have added a class to my project implementing ClassImp and ClassDef.

I have generated the dictionary using: rootcint -f mMDict.C -o inc/mMBackground.h

Then I compile the mMDict.C as I compile the rest of files in my project.

I generate a shared library with g++ -shared -o objects + mMDict.o

Then I generate my executable using the shared library without any warnings …

When I execute my program it seems to work, but the root file that I have generated with the code:

    sprintf(fName, "%s%s\n", ROOT_PATH, "background.root" );
    TFile *f = new TFile( fName,"RECREATE");

    mMBackground *back = new mMBackground();
    TTree *tree = new TTree( treeName, treeName);
    tree->Branch("background", &back);

         I set the values in back Class


And the root file that I get is: background.root? ( unreadable in root enviroment)

Any Idea?

Note: If I try to link my shared library ( with “ld -shared” in twice of “g++ -shared” I get a problem when trying to link the executable:

g++ -o bin/mM-V -I$ROOTSYS/include -Iinc -L$ROOTSYS/lib -Llib mM.cxx -lCore -lCint -lMatrix -lmM -lshift -lHist -lTree

/usr/bin/ld: bin/mM-V: hidden symbol `__dso_handle’ in /usr/lib/gcc/x86_64-redhat-linux/3.4.6/crtbegin.o is referenced by DSO
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: ld returned 1 exit status

Thanks for helping


I have discovered that the file generated: background.root? is ok. I am able to read it if I change the strange filename and I load the library in the root enviroment.

However, this is a bit disturbing, do you know why this strange filename with “?” ending?

Thanks a lot

Could you send the shortest possible (but RUNNING) script reproducing the problem?


why would you want to end your filename on a newline?! Remove the ‘\n’ from the sprintf statement.