Can I create static c callable library?
H. S. Teoh
hsteoh at quickfur.ath.cx
Thu Sep 27 21:41:31 UTC 2018
On Thu, Sep 27, 2018 at 03:11:26PM -0600, Jonathan M Davis via Digitalmars-d-learn wrote:
> On Thursday, September 27, 2018 6:16:13 AM MDT Atila Neves via Digitalmars-
> d-learn wrote:
[...]
> > Even easier, compile this C file and add the resulting object
> > file to your (now mostly) D static library:
> >
> > -----------------------
> > extern int rt_init(void);
> > extern int rt_term(void);
> >
> > __attribute__((__constructor__)) void dinit(void) {
> > rt_init();
> > }
> > __attribute__((__destructor__)) void dterm(void) {
> > rt_term();
> > }
> > -----------------------
> >
> > The C runtime will initialise the D runtime for you.
>
> That's a neat trick.
[...]
Indeed!
Though I'm not sure what will happen if your C program tries loading two
or more D libraries that use this trick... is rt_init() idempotent? If
not, it could lead to a fun mess on startup... :-D It also doesn't
address the very thorny issue of how to make multiple D libraries work
nicely with each other's copy of druntime, or how to make them share a
single druntime.
T
--
Без труда не выловишь и рыбку из пруда.
More information about the Digitalmars-d-learn
mailing list