|There's more than one way to do things|
Dynaloader/XS: sharing C symbols across shared objectsby creamygoodness (Curate)
|on Jun 10, 2008 at 00:41 UTC||Need Help??|
creamygoodness has asked for the
wisdom of the Perl Monks concerning the following question:
I have two XS modules, and I would like C symbols loaded by one to be accessible from the other. The ultimate goal is to avoid including the Snowball stemming library in the KinoSearch distribution, with all of its compilation overhead, but instead load Lingua::Stem::Snowball and its associated shared object and have the Snowball C API be accessible from within the KinoSearch shared object.
This works fine on Mac OS X, but not on FreeBSD or Linux. The easiest way to demonstrate the problem is to use Inline C.
Here's the Hello.pm perl module:
Here's the hello_goodbye.pl perl script:
The script works fine on OS X...
... but fails on Linux...
... and FreeBSD:
Can anyone explain this behavior, and perhaps suggest a solution?
Update: RESOLVEDThe default behavior for dynamically loading shared objects via the C function dlopen() is not to export symbols. To override when the loading happens via Perl, it's necessary to switch out XSLoader for the more complex but powerful Dynaloader and set some flags. Here's the patch to Lingua::Stem::Snowball:
Thanks to Rob for pointing me in the right direction. References:
Rectangular Research ― http://www.rectangular.com