dynamic library building and loading

Daniel Kozak kozzi11 at gmail.com
Wed Sep 26 23:13:16 PDT 2012


Hi,

I have same issue, but it is possible make shared library,
first of all you have to make shared variant of druntime and 
phobos library, than it should work ok.

Now I am at work, when I come back home I will post some more 
details about this.

Daniel Kozak

On Wednesday, 26 September 2012 at 17:57:29 UTC, 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:
>
> *** Makefile
> all: main lib.so
>
> main: main.d
> 	dmd main
>
> lib.so: lib.d
> 	dmd -fPIC -shared lib.d -of./lib.so
>
> *** lib.d
> extern(C) int fun(string s)
> {
>     return 42;
> }
>
> *** main.d
> import std.stdio;
> void main()
> {
> }
>
> 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?
>
>
> Thanks,
>
> Andrei




More information about the Digitalmars-d mailing list