"David M. Lloyd" wrote:
> Is there a standard, platform-independant way I can export some C function
> names from my XS module that allows other modules to use them?
I've done this on Solaris by expressing an explicit linker dependency
between the calling XS module and the called XS module, that way when the
calling module is loaded via dlopen() the called module automatically gets
loaded and linked by the dynamic linker. The subsequent dlopen() of the
called module by DynaLoader just returns a reference to the already-loaded
module.
The appropriate magic is to put the following in the parameter list of the
callers WriteMakefile:
dynamic_lib => { OTHERLDFLAGS =>
'-h Caller.so ' .
'-R\$$ORIGIN/../Callee $(INST_ARCHAUTODIR)/../Callee/Callee.so ' .
},
And this in the callees:
dynamic_lib => { OTHERLDFLAGS => '-h Callee.so' },
the '-h' defines the soname of the shared object, so that the linker can tie
together the caller and callee. The -R\$$ORIGIN/../Callee tells the linker
where to look for the callee relative to the caller, so you don't have to
diddle around with LD_LIBRARY_PATH.
Here is what you end up with:
$ dump -Lv Caller.so
**** DYNAMIC SECTION INFORMATION ****
.dynamic:
[INDEX] Tag Value
[1] NEEDED Callee.so
:
[6] SONAME Caller.so
[7] RUNPATH $ORIGIN/../Callee
[8] RPATH $ORIGIN/../Callee
:
Unfortunately this fails the 'portable' bit of the requirement, as it is
Solaris-specific. It is a neat trick however, and it avoids all that
tedious mucking about with having to implement your own vtables :-)
--
Alan Burlison
--
$ head -1 /dev/bollocks
conceptualize horizontal design patterns