Howto compile a library to extend ROOT in MacOSX

I have wrote a code compiled as shared library on a Linux machine to define a set of classes and functions. All work fine without any problem. An user now likes to use this library under a MacOSX machine.

How to compile the code to generate a library that can be loaded by ROOT?


I would go via ACLiC: Create a source file (say MyLib.C) that #includes all the sources of your library, add a pragma link line for each of your classes at the end of MyLib.C like so:

#ifdef __MAKECINT__ #pragma link C++ class MyClass+; #endif

Then any user can build your library on any platform by simply running “.L MyLib.C+”, and it automatically comes with a dictionary.

Cheers, Axel.

Sorry for the delay. The problem that I have is a bit different. I have a custom Makefile building a valid shared library. I’m using this Makefile successfully under Linux but if a try to use it in a MacOSX environment I receive an error producing the shared library.

The final command that works under Linux, and fails on Mac OSX, is:

where in Linux:

which are the correct flags for OSX?

see example in $ROOTSYS/test/Makefile and look around line 253 (depending which version of macosx you use).


Sorry for delay in the answer, anyway I tried to use your suggestion but I failed. when I try to load the library I receive the following error message:

[code]========== STACKS OF ALL THREADS ==========

Thread 1 (process 3010 thread 0x20b):
#0 0x90fab4b5 in wait4 ()
#1 0x90fa9007 in system$UNIX2003 ()
#2 0x0088a1a1 in TUnixSystem::StackTrace ()
#3 0x0088e3e5 in TUnixSystem::DispatchSignals ()
#4 0x0088e558 in SigHandler ()
#6 0x8fe13add in
__dyld__ZN16ImageLoaderMachO8preFetchEiyRKN11ImageLoader11LinkContextE ()
#7 0x8fe14b24 in
#8 0x8fe05bec in
#9 0x8fe05f71 in
__dyld__ZN4dyld10loadPhase4EPKcRKNS_11LoadContextEPSt6vectorIS1_SaIS1_EE ()
#10 0x8fe06445 in
__dyld__ZN4dyld10loadPhase3EPKcRKNS_11LoadContextEPSt6vectorIS1_SaIS1_EE ()
#11 0x8fe069ac in
__dyld__ZN4dyld10loadPhase1EPKcRKNS_11LoadContextEPSt6vectorIS1_SaIS1_EE ()
#12 0x8fe06a73 in
__dyld__ZN4dyld10loadPhase0EPKcRKNS_11LoadContextEPSt6vectorIS1_SaIS1_EE ()
#13 0x8fe06bd2 in __dyld__ZN4dyld4loadEPKcRKNS_11LoadContextE ()
#14 0x8fe0ba3f in __dyld_dlopen ()
#15 0x90f46a22 in dlopen ()
#16 0x01135b67 in G__dlopen ()
#17 0x01138130 in G__shl_load ()
#18 0x010b2362 in G__loadfile ()
#19 0x01101b4f in G__process_cmd ()
#20 0x00864614 in TCint::ProcessLine ()
#21 0x007da0f7 in TApplication::ProcessLine ()
#22 0x0002ff37 in TRint::HandleTermInput ()
#23 0x0002f600 in TTermInputHandler::Notify ()
#24 0x000314a4 in TTermInputHandler::ReadNotify ()
#25 0x0088e6f0 in TUnixSystem::CheckDescriptors ()
#26 0x0088ee1b in TUnixSystem::DispatchOneEvent ()
#27 0x00827480 in TSystem::InnerLoop ()
#28 0x0082a05b in TSystem::Run ()
#29 0x007d8f13 in TApplication::Run ()
#30 0x000307de in TRint::Run ()
#31 0x00001bae in main ()
Root > [/code]

the flagslibrary I used to create the library are:

SOFLAGS = -dynamiclib -single_module -undefined dynamic_lookup [/code]

It seems that you have a function declared in a header file but not implemented. I would need your code to investigate.
I strongly suggest to use ACLIC to load your code instead of building a shared lib and loading it, ie

gROOT->ProcessLine(".L mycode.C+");

Ok, I’ll check but I’m not the owner of the Mac and this will delay the answer.

Anyway what is surprising me is that the code (a bunch of c++ classes with their dictionaries) is correctly compiled and loaded ina Linux system. Are the ROOT compilation/linking flags under MacOSX as Linux?

Thanks, again.


Compilation flags are not identical. see