Creating shared object libraries containing TF1s on OSX

Hello ROOTers,
I am trying to create a shared object library of a class that contains a TF1, generated from a member function of another class (Type E described in root.cern.ch/root/html/TF1.html). It seems that, on OSX 10.5.6 (intel), the library does not work correctly when the TF1 is involved. I have reproduced the bug by gutting one of the test programs (see attached). The test creates two executables: Event and Event_no_lib. Event is created using the shared object library, and Event_no_lib is created using the objects. On my machine, Event_no_lib runs and Event does not, while on a friend’s linux machine, both run just fine. I am using the exact syntax from the examples to create my libraries. I would appreciate any help!
SOTest.tar.gz (4.4 KB)

Hi,

This is problem of library initialization order.
In your code you have 2 global/static variables (fSubevent and fFunction).
fFunction must be created only after the ROOT library have been initialized. When using the library, since you listed libEvent first, this is initialized first (on MacOS) and hence the crash. A weak, platform dependent workaround is to list libEvent last on the link line.

A much better work-around is to delay the initialization of you static variable by either getting rid of their staticness or by making then ‘function’ static.

Cheers,
Philippe.

Hi Philippe,
Thanks! That did the trick.

  • T.J.