Dear (Mac-)ROOTers,
I am having trouble producing and using a ROOT shared library under MacOSX. I have Mac OSX 10.4.9, gcc 4.0.1. My ROOT version is 5.15/08
(so don’t tell me to upgrade to the latest version!).
I am trying to build the simplest possible shared library, starting from the
canonical three files myClass.cc, myClass.h and myClass_LinkDef.h
#include "myClass.h"
ClassImp(myClass)
myClass::myClass() {} // Constructor
myClass::~myClass() {} // Destructor
myClass.h:
#include "TObject.h"
class myClass : public TObject
{
public:
myClass(); // Constructor
~myClass(); // Destructor
ClassDef(myClass,1)
};
myClass_LinkDef.h:
#ifdef CINT
#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ class myClass+;
#endif
I compile myClass with -fPIC option:
g++ myClass.cc -c root-config --cflags --libs
-fPIC
No problem, this gives me myClass.o
Then I create the dictionary file:
rootcint -f myClass_dict.cc -c myClass.h myClass_LinkDef.h
again no problem, I get myClass_dict.cc and myClass_dict.h
as expected, let’s compile those too:
g++ myClass_dict.cc -c root-config --cflags --libs
-fPIC
Now we’re ready to build our shared library:
On my LINUX box, I would just do
g++ -shared -o myClass.so myClass.o myClass_dict.o
which gives me myClass.so, which I can then load in a ROOT
session like this:
root [0] gSystem->Load("./myClass.so");
On MacOSX, I presume the corresponding command is simply
g++ -dynamic -o myClass.so myClass.o myClass_dict.o
but this gives me
/usr/bin/ld: Undefined symbols:
_main
TVersionCheck::TVersionCheck(int)
ROOT::TGenericClassInfo::SetImplFile(char const*, int)
etc. (many more methods are listed)
Why does the linker insist on _main, I just want a class packaged as
a shared library! Does anyone know what I’m doing wrong here?
Many thanks in advance!
Thomas