Simple way to create and merge shared libraries?

Hello,
I have n TObject-derived classes (First.C, First.h and Second.C, Second.h etc.) and I would like to create a shared library containing all of them. How can I do this in a simple way? Since I use a Makefile for the rest of my analysis code, I thought a manual g++ing could be the solution, but I have no clue on how to achieve this, and perhaps there is some trick as simple as “.L First.C++”…

Thank you in advance!

VIVE L’AMOUR!
how about you create a file “MyCode.cxx” which contains:

#include “First.C”
#ifdef MAKECINT
#pragma link C++ defined_in “First.h”;
#pragma link C++ defined_in “First.C”;
#endif

#include “Second.C”
#ifdef MAKECINT
#pragma link C++ defined_in “Second.h”;
#pragma link C++ defined_in “Second.C”;
#endif

#include “Third.C”
#ifdef MAKECINT
#pragma link C++ defined_in “Third.h”;
#pragma link C++ defined_in “Third.C”;
#endif

void MyCode(void) {} // “dummy” startup routine

Then you simply do “.L MyCode.cxx++”, or “.x MyCode.cxx++” at the ROOT prompt.
This will create “MyCode_cxx.so”, but you can simply rename it into “MyCode.so” or “libMyCode.so” and use it as any other shared library afterwards. :-({|=
One can easily write a simple shell script which will automatically create “MyCode.cxx” from a given set of “filenames” (given as parameters to this shell script, e.g. “MyCode.sh”, something like “sh MyCode.sh First Second Third” ), or one could even write a simple ROOT macro which would do the same thing (including creation of the shared library itself). <img src="/uploads/default/original/2X/8/84c2fe9464a4066c00e1bd5978e913e7869cbb07.gif" width=“22” height=“16” alt=":-"" title=“Whistle”/>

I am stupid. No?
Pepe Le Pew.

This does not work, since my classes inherit from TObject, and I’d have to remove ClassImp from all but one of the sources…

VIVE L’AMOUR!
as far as I remember, you need “ClassDef” / “ClassImp” macros for a class only if you want to use ROOT I/O on its objects. So, if you do NOT need it, you can remove them (even if the class inherits from TObject).
If you need ROOT I/O on its objects, then I have no simple solution. In this case I would create a hand-written “linkdef” file (containing “#pragma” lines for all classes, etc.), parse it with rootcint, then compile every source code file separately and finally create the shared library.
A pitiful case, am I not?
Pepe Le Pew.

Maybe you can also try this simple trick … execute the following shell commands …

cat First.h Second.h Third.h > MyCode.hxx
echo ‘#ifndef MAKECINT’ >> MyCode.hxx
echo '#include “First.C” ’ >> MyCode.hxx
echo '#include “Second.C” ’ >> MyCode.hxx
echo '#include “Third.C” ’ >> MyCode.hxx
echo ‘#endif’ >> MyCode.hxx

Then try:
[…] > root
root [0] .L MyCode.hxx++

[quote]as far as I remember, you need “ClassDef” / “ClassImp” macros for a class only if you want to use ROOT I/O on its objects. So, if you do NOT need it, you can remove them (even if the class inherits from TObject).[/quote]Please note that neither ClassDef nor ClassImp is needed to to ROOT I/O. All you need for ROOT I/O is to generate the dictionary for the class.

Note that ClassDef provides an optimizations, object with a ClassDef will be smaller on file and will be read slightly faster. Also customizing schema evolution would be easier (since the ‘old version’ can easily be refered to with the ClassDef number they had).

Note that ClassImp is need only if you want to be able to produce the documentation for your class using THtml.

Note that inheriting from TObject (which also requires the use of ClassDef) allows your object to be stored in the ROOT collection, in particular in a TClonesArray; However with or without the inheritance from TObject you can store the object in a TTree (i.e. anything with a dictionary can go in a TTree).

Cheers,
Philippe.

Hi,

[quote]This does not work, since my classes inherit from TObject, and I’d have to remove ClassImp from all but one of the sources…[/quote]Why? How does it fails? Did you retry with v5.28?

Philippe.

[quote]Since I use a Makefile for the rest of my analysis code, I thought a manual g++ing could be the solution[/quote]You need to generate, compile and link a dictionary. Use a linkdef.h file:#ifdef __MAKECINT__ #pragma link C++ class First+; #pragma link C++ class Second+; #pragma link C++ class Third+; #endifand rootcint -f dict.cxx -c First.h Second.h Third.h linkdef.h
and finally compile and link the resulting dict.cxx

Cheers,
Philippe.

VIVE L’AMOUR!
well, it seems I misinterpreted some of the statement that I found in the documentation a long time ago (or maybe things changed significantly with time).

Would it be possible that you add your explicit notes about the usage of “TObject”, “ClassDef” and “ClassImp” to the “Motivation” section in the “Adding a Class” chapter of the “User’s Guide”?

I am stupid. No?
Pepe Le Pew.

Will do.

Philippe.