dynamic library building and loading
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Wed Sep 26 10:58:12 PDT 2012
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