Compiling to shared library with static dependencies
Tanel L via Digitalmars-d
digitalmars-d at puremagic.com
Wed Dec 14 04:33:04 PST 2016
Hello,
I am very new to the D world - but serious in moving over to it
after I have seen what a cool language it really is.
I am trying to incorporate D into our main product as an
externally loadable module.
Basically I have a minimal project:
./app.d
./helpers/image.d (mir and dcv libraries imported)
./helpers/utils.d
I am using the latest (statically compiled) ldc2
In my app file(besides the void main) I have a test function
which I am trying to call from python using ctypes:
extern (C) int doit()
Currently I have gotten as far as getting a loading error in
python:
library.so: undefined symbol: _d_eh_personality
Googling disclosed that this is satisfied by libdruntime.so, but
I don't have a shared libdruntime anywhere. I guess I have to
compile ldc2 in dynamic mode and use the libdruntime.so from
there?
My build steps until now:
dub.sdl (pseudocode):
project_description "nudesc"
dependency "mir"
dependency "dcv"
targetPath "lib"
dflags "-relocation-mode=pic"
dub build --compiler ldc2
cp .dub/obj/*.o lib/
cd lib
ldc2 -of library.so helpers.image.o helpers.utils.o nudesc.o
-shared -defaultlib=phobos2
strace shows that ldc2 loads "phobos2" from DMD:
"/usr/lib/gcc/x86_64-linux-gnu/5/../../../x86_64-linux-gnu/libphobos2.so"
The LDC2 folder only seems to contain libphobos2-ldc.a, no .so's.
Compilation succeeds, but trying to load the so from python:
python -c "from ctypes import *; CDLL('library.so',
mode=RTLD_GLOBAL)"
OSError: library.so: undefined symbol: _d_eh_personality
I figured that I don't have druntime.so available because
druntime is incorporated into LDC2, but mine is statically
compiled (downloaded precompiled from github i think).
So I tried to compile LDC2 dynamically:
cmake .. -DBUILD_SHARED=ON
But I get a bunch of these errors before the LDC2 build fails:
/home/tanel/thirdparty/ldc-dynamic/build/bin/ldc2: error while
loading shared libraries: libldc.so: cannot open shared object
file: No such file or directory
runtime/CMakeFiles/druntime-ldc.dir/build.make:93: recipe for
target 'runtime/src/core/bitop.o' failed
make[2]: *** [runtime/src/core/bitop.o] Error 127
Basically I am cornered... I really need to be able to compile
dcv and mir into my dynamic libraries. Probably LDC2 is a must
because DMD and GDC have given me compilation errors on the
project even in regular mode. Also LDC2 seems to be the best.
Any ideas what to do or how to proceed?
Thanks a bunch!
More information about the Digitalmars-d
mailing list