[dmd-internals] Making druntime a shared library on linux

Walter Bright walter at digitalmars.com
Mon Mar 25 12:46:46 PDT 2013


If you're making a D shared library, you'll need to use a shared library version 
of druntime for both the executable and your shared library. Otherwise, there 
will be two instances of druntime, and There Can Be Only One.

I have 3 pull requests in to do this:

https://github.com/D-Programming-Language/druntime/pull/462
https://github.com/D-Programming-Language/phobos/pull/1223
https://github.com/D-Programming-Language/dmd/pull/1798

What these do is:

1. build druntime as a shared library, need -defaultlib= to do that

2. split libdruntime.a off from libphobos2.a, so now the following flags must be 
passed to the link step:

      -lphobos2 -ldruntime

3. add the ability to link to the shared library version of druntime instead, 
with -shared-druntime flag to dmd:

     -lphobos2 -ldruntimeso

I couldn't find a linker flag to prefer libdruntime.so over libdruntime.a, or 
vice versa, so I named the shared library libdruntimeso.so. Ugh. If there's a 
better way, please let me know.

This is currently linux only, until we get things ironed out.

If you want to try out the shared druntime, you'll need to set LD_LIBRARY_PATH. 
I set mine to:

LD_LIBRARY_PATH=/home/walter/cbx/mars/phobos/generated/linux/64:/home/walter/cbx/mars/phobos/generated/linux/32


More information about the dmd-internals mailing list