dynamic library building and loading

Jacob Carlborg doob at me.com
Wed Sep 26 12:18:58 PDT 2012


On 2012-09-26 19:58, Andrei Alexandrescu wrote:
> Haven't done any dynamic linking with D and I need to. I'm using dmd
> 2.058/Linux at work to build and use dynamic libraries. Here's my attempt:

> Running make prints:
>
> dmd -fPIC -shared lib.d -of./lib.so
> /usr/bin/ld:
> /mnt/vol/engshare/third-party/centos5.2-native/dmd/dmd-2.058-centos5.2-native/bin/../../../../centos5.2-native/phobos/phobos-2.058/ffad884/generated/linux/release/64/libphobos2.a(minfo.o):
> relocation R_X86_64_32 against `a local symbol' can not be used when
> making a shared object; recompile with -fPIC
> /mnt/vol/engshare/third-party/centos5.2-native/dmd/dmd-2.058-centos5.2-native/bin/../../../../centos5.2-native/phobos/phobos-2.058/ffad884/generated/linux/release/64/libphobos2.a:
> could not read symbols: Bad value
> collect2: ld returned 1 exit status
>
> What steps do I need to take to get off the ground?

You need to properly implement support for dynamic libraries in druntime 
and DMD. I'm not entirely sure if there are some problems left in DMD, 
but druntime is definitely  not ready yet.

In general what needs to be done is to properly handle:

* Module infos
* TLS
* Exception handling tables

Martin Nowak has a branch for this:

https://github.com/dawgfoto/druntime/tree/SharedRuntime

-- 
/Jacob Carlborg


More information about the Digitalmars-d mailing list