Apache "mod_d" needs C to instantiate D interpreter?

JFD jfd at nospam.com
Wed Nov 10 16:19:53 PST 2010


== Quote from Jacob Carlborg (doob at me.com)'s article
> On 2010-11-09 01:37, JFD wrote:
> > Yes, you're right.  One should implement Apache module in D.
> >
> > One thing is that Apache module entry point expects a "C" function.  I've figure
> > that that one could just add extern(C) in front of D function to be callable from
> > C, so that was easy.  Also, Apache expects .so shared library, and one could build
> > it roughly like this:
> >
> > Let DMD build a .a library:
> > dmd -fPIC -lib libhello.d
> >
> > Then convert it to shared library:
> > gcc -shared -Wl,-soname,libhello.so.0 -o libhello.so.0.0 libhello.a
> >
> > Could DMD build .so shared library directly (did I miss something)?
> >
> > Then it's all D from there on.  Cool!
> >
> > Thank you.
> Dynamic libraries doesn't work currently with DMD on Linux. They do work
> with DMD using Tango on Mac OS X where DMD also can build dynamic
> libraries directly (with the -dylib flag).

I did some tests, here's the result: Apache module (.so shared library) written in
C is working fine when linked with D shared library built by GDC (4.3.4), as
something like this:

gdc -fPIC -c libfoo.d -o libfoo.o
gdc -shared -Wl,-soname,libfoo.so.0 \
  -o libfoo.so.0.0 libfoo.o -lc

It looks like one could potentially also write the Apache module entirely in D,
too, after matching some data types, but I haven't tried it yet.

Too cool!  Someone could start writing Apache module for D language web
applications anytime... :)

I can call  GDC-built D shared library from C executable or C shared library
without problem.  And it's working with phobos.

It appears that DMD currently cannot create shared library on Linux, as you said.
 It can however create static library (.a) as above.  C executable program is
working fine with it.  But C shared library that calls D static library gets stack
error when the shared library is loaded.


More information about the Digitalmars-d mailing list