Creating shared library object on OS X 10.5 Leopard

Hi all,

I am having a problem generating a shared library for a class which I want to store/read from TTrees in OS X 10.5, running root 5.19/02. The following commands work on a Debian machine running root 5.16:

rootcint -f MyClassDict.cc -c MyClass.h
g++ -o MyClass.o `root-config --cflags` -fPIC -I. -c MyClass.cc
g++ -o MyClassDict.o `root-config --cflags` -fPIC -I. -c MyClassDict.cc
g++ `root-config --libs --ldflags` MyClass.o MyClassDict.o -shared -Wl,-soname,libMyClass.so -o libMyClass.so

which returns “ld: unknown option: -soname”. After a brief search, I find that Darwin doesn’t use the -soname flag, and it is instead replaced by -dylib_install_name, so the last line becomes

g++ `root-config --libs --ldflags` MyClass.o MyClassDict.o -shared -Wl,-dylib_install_name,libMyClass.so -L. -o libMyClass.so

which generates the response

and now I’m stumped on how to proceed. Any suggestions?

Thanks,
~Ben

HI,

try:

 g++ -m64 -m64 -dynamiclib -single_module -undefined dynamic_lookup Event.o EventDict.o -o  libEvent.so

that is -dynamiclib instead of -shared.

In general have a look in $ROOTSYS/test/Makefile.arch

Cheers, Fons.

great! it worked out. I do have another request from this for people like myself who are not very fluent with Makefile scripting and compiler flags:

How hard would it be to add an extra flag to root-config to handle the system-depended shared library flags, so that one could use for example

g++ `root-config --ldflags --soflags` Event.o EventDict.o -o libEvent.so

I know shared library generation flags are not root-specific and therefore don’t really belong in root-config; on the other hand, if it would not be too difficult to implement, it would make a lot of tasks easier!

Thanks,
~Ben

Hi Ben,

Alternatively you can use ACLiC to generate the dictionary and the library in one simple go :slight_smile:
root [] .L myfile.cxx+

Cheers,
Philippe

Hi Phillipe,

This is true, but it doesn’t work well with Makefiles… :slight_smile:

Actually with a bit of script magic, it works pretty well. Almost all the shared library in our roottest suite are created via a Makefile calling ACLiC.

See root.cern.ch/viewcvs/trunk/?root=roottest
and in particular:
root.cern.ch/viewcvs/trunk/scrip … t&view=log
and
root.cern.ch/viewcvs/trunk/scrip … t&view=log

Cheers,
Philippe.

Actually with a bit of script magic, it works pretty well. Almost all the shared library in our roottest suite are created via a Makefile calling ACLiC.

See root.cern.ch/viewcvs/trunk/?root=roottest
and in particular:
root.cern.ch/viewcvs/trunk/scrip … t&view=log
and
root.cern.ch/viewcvs/trunk/scrip … t&view=log

Cheers,
Philippe.

PS. Of course ACLiC is not the panacea and some complex things are still easier by calling directly the compiler and the linker.