26.09.2012 21:58, Andrei Alexandrescu пишет:
> 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.
Sorry for the OT (as you are a Linux user), but if you will ever do it on Windows, be aware of this nasty trap:
http://d.puremagic.com/issues/show_bug.cgi?id=8130--
Денис В. Шеломовский
Denis V. Shelomovskij

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

On 9/26/12 2:25 PM, Denis Shelomovskij wrote:
> 26.09.2012 21:58, Andrei Alexandrescu пишет:
>> 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.
>> Sorry for the OT (as you are a Linux user), but if you will ever do it
> on Windows, be aware of this nasty trap:
> http://d.puremagic.com/issues/show_bug.cgi?id=8130
Thanks!
Andrei

On Wednesday, 26 September 2012 at 20:10:47 UTC, Michael wrote:
>> Thanks. The loading part is very useful, but I'm still lost when it comes to build the shared library itself.
>>>> Andrei
>> Program loads dll at runtime using loader which is configured to load concrete dll file(s). Like in gtkD http://www.dsource.org/projects/gtkd/browser/trunk/src/gtkc/Loader.d
Loading Shared lib isn't big issues here.
The bigger one is building Shared library (written in D) and running it in host application without issues (EH, shared GC etc).
Andrei, if you find out how to make those things work, please share your findings. I'm also in need of using shared libraries.
And yeah, probably Martin Nowak will be the best bet to get information from.

> Loading Shared lib isn't big issues here.
>> The bigger one is building Shared library (written in D) and running it in host application without issues (EH, shared GC etc).
>> Andrei, if you find out how to make those things work, please share your findings. I'm also in need of using shared libraries.
>> And yeah, probably Martin Nowak will be the best bet to get information from.
I understand. As I remember on forum were topic with same approach for dll written in D. But I can't find a link.