Plugins and D programs
Martin Nowak
code at dawg.eu
Sat Mar 15 13:50:07 PDT 2014
On 03/13/2014 02:22 PM, Steve Teale wrote:
>
> main : ifd.d main.d
> dmd -c ifd.d
> dmd -c main.d
> dmd main.o ifd.o -L-ldl -defaultlib=libphobos2.so -L-rpath=.
>
> plugin : plugin.d
> dmd -c -shared -fPIC plugin.d
> dmd plugin.o -shared -defaultlib=libphobos2.so -map
>
> clean :
> rm *.o
> rm main
> rm plugin.so
One problem here is that main and the plugin share the definitions in
ifd.d. Therefor you need to move the interface into it's own shared
library and link both (main and any plugin) against the interface
definition.
main : main.d ifd
dmd -c main.d
dmd main.o -L-ldl -defaultlib=libphobos2.so -L-rpath=. -L./ifd.so
plugin : plugin.d ifd
dmd -c -shared -fPIC plugin.d
dmd plugin.o -shared -defaultlib=libphobos2.so -L./ifd.so
ifd : ifd.d
dmd -c -shared -fPIC ifd.d
dmd ifd.o -shared -defaultlib=libphobos2.so
clean :
rm *.o
rm main ifd.so plugin.so
Note that it was possible to load plugin.so even though it has undefined
symbols because we link with -L--export-symbols (for backtrace symbols).
This linker flag causes the main executable to export it's symbols, so
the plugin will resolve it's undefined symbols by using the ones from
main. I'm still investigating why it crashes when using --export-dynamic
though.
More information about the Digitalmars-d
mailing list