shared libraries in D
Jacob Carlborg
doob at me.com
Tue Feb 15 11:21:53 PST 2011
On 2011-02-15 16:02, Johannes Pfau wrote:
> Iain Buclaw wrote:
>> Came across this obscure documentation in the tldp.
>>
>> "Libraries should export initialization and cleanup routines using the
>> gcc __attribute__((constructor)) and __attribute__((destructor))
>> function attributes."
>>
>> This is what gdc was doing anyway.
>>
>>
>> "Constructor routines are executed before dlopen returns (or before
>> main() is started if the library is loaded at load time). Destructor
>> routines are executed before dlclose returns (or after exit() or
>> completion of main() if the library is loaded at load time)."
>>
>> This is what should have been happening, but wasn't earlier because:
>>
>>
>> "Shared libraries must not be compiled with the gcc arguments
>> `-nostartfiles' or `-nostdlib'. If those arguments are used, the
>> constructor/destructor routines will not be executed (unless special
>> measures are taken)."
>>
>> Whoops! Fixed and it now works. :~)
>>
>> Will be making shared libraries default in GDC pretty soon now...
>
> Great, now I've got 2 questions:
>
> 1.) Are shared libraries compiled with gdc abi compitible with dmd?
> (if dmd did support shared libraries)
I'm not completely sure but the runtimes are different.
> 2.) Is it now possible to load a shared d library into a C program? Will
> jut loading the library initialize the runtime or is it necessary to
> call some runtime setup functions manually? If the C program loads 2 D
> libraries, will those share the gc/runtime?
I don't know how Iain has implemented this but it should be easy to do.
Just add, to the runtime, a C function with __attribute__((constructor))
that initializes the runtime.
--
/Jacob Carlborg
More information about the Digitalmars-d
mailing list