Comment #0 by timothee.cour2 — 2014-02-18T00:44:37Z
Now that issue 11478 is partially fixed (linktime shared libraries), on to runtime loaded shared libraries:
----
module foo;
import std.stdio;
extern(C) void foo1(){
printf("ok1\n");
import core.runtime;
bool ret=Runtime.initialize(); //is it necessary?
printf("ret=%d\n",ret);
printf("ok2\n");
writeln("ok3");
int[]a;
a.length=2; //ok
writeln(a.length); //dmd2.062 only crashes at this point
}
----
module main2;
import std.stdio, core.sys.posix.dlfcn;
void main(){
string file="libfoo.dylib";
auto handle = dlopen(file.ptr, RTLD_LAZY | RTLD_GLOBAL);
auto funptr = cast(void function()) dlsym(handle, "foo1");
funptr();
}
----
dmd -oflibfoo.dylib -shared foo.d;
dmd main.d
./main
--output:
2.062:
crashes at writeln(a.length) (lldb shows it crashes inside LockingTextWriter), which can still be useful for writing plugins.
git head: crashes upon loading
Also, note that dlopen() of a D shared library works when called from a C++ file, and that a C++ file can call multiple D shared libraries simultaneously when using RTLD_LAZY option.
Before waiting for a full solution with an integrated druntime, is there at least a way to have a separate runtime in each shared library, so that dlopen() can be called from a D file?
Comment #1 by bugzilla — 2014-06-20T20:52:41Z
It appears from the text here that this is not a regression since it never did work. Reclassified.
Comment #2 by robert.schadek — 2024-12-13T18:16:58Z