shared libraries in D

Iain Buclaw ibuclaw at ubuntu.com
Mon Feb 14 08:32:30 PST 2011


== Quote from Iain Buclaw (ibuclaw at ubuntu.com)'s article
> == Quote from Johannes Pfau (spam at example.com)'s article
> > --Sig_/a6ST_/ke_QlFF5lFi4BGNvw
> > Content-Type: text/plain; charset=US-ASCII
> > Content-Transfer-Encoding: quoted-printable
> > Iain Buclaw wrote:
> > >So I've been prototyping, and have built a fully working shared D2
> > >druntime/phobos library on Linux (will come to caveats in a moment).
> > >Just for sake of visual proof.
> > Awesome!
> > >
> > >Before I progress, posting to ask if anyone has any good
> > >implementation ideas to get this fully functional?
> > >
> > >Regards
> > >Iain
> > I think dmd/druntime support shared libraries on MacOS. I'm not sure
> > though whether that also includes using a shared  druntime/phobos.
> > Probably that code could help (or maybe the MacOS code is too
> > different, then just ignore this comment ;-))
> > --=20
> > Johannes Pfau
> The support for OSX uses an entirely different, and questionable implementation.
> Regards

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...


More information about the Digitalmars-d mailing list