Bug 7870 – Shared library support for Linux is missing

Status
RESOLVED
Resolution
FIXED
Severity
normal
Priority
P2
Component
dmd
Product
D
Version
D2
Platform
x86
OS
Linux
Creation time
2012-04-09T00:00:00Z
Last change time
2015-06-09T05:14:50Z
Keywords
dll
Assigned to
code
Creator
timo.westkamper

Comments

Comment #0 by timo.westkamper — 2012-04-09T00:00:21Z
Shared library creation for Linux via dmd doesn't work. Here is my latest test: * test.d: import std.stdio; extern (C) { void hiD() { writeln("hi from D lib"); } } * main.c #include <stdio.h> #include <dlfcn.h> #include <stdlib.h> void main() { void (*hiD)(void); void* handle = dlopen("./libtest.so", RTLD_LAZY); if (handle == NULL) { printf("%s\n", dlerror()); exit(1); } hiD = dlsym(handle, "hiD"); if (hiD != NULL) { hiD(); } else { printf("hiD is null\n"); } dlclose(handle); } * Makefile #!/bin/bash test: #gdc-4.6 -g -c test.d -fPIC -o test.o #gdc-4.6 -shared -o libtest.so -fPIC test.o -lc -nostartfiles dmd -g -c test.d -fPIC ld -shared -o libtest.so test.o -lrt -lphobos2 -lpthread gcc -g main.c -ldl -lpthread ./a.out clean: rm -rf *.so *.o *.out With this setup I get ./libtest.so: undefined symbol: _deh_beg With a fake main method added I get make: *** [test] Segmentation fault This is what I get from gdb Program received signal SIGSEGV, Segmentation fault. 0xb7fd1ed3 in std.stdio.__T7writelnTAyaZ.writeln() (_param_0=...) at /usr/include/d/dmd/phobos/std/stdio.d:1550 1550 enforce(fprintf(.stdout.p.handle, "%.*s\n", I am using dmd 2.058 on Ubuntu 11.10 (32 bit) With gdc I get different errors, but it seems even more difficult to get it working.
Comment #1 by timo.westkamper — 2012-04-14T08:30:56Z
Comment #2 by code — 2014-06-15T19:50:21Z
This issue has been resolved, you can look at https://github.com/D-Programming-Language/druntime/tree/master/test/shared for how to load/init/term a D shared library from a C host.