Hi,

I am trying to use a D static library from C on Mac OSX Lion, but it always fails.

--- file mylib.d ---
module mylib;
import core.runtime;

extern(C) {
        bool mylib_init() {
                return Runtime.initialize();
        }
        
        bool mylib_free() {
                return Runtime.terminate();
        }
}
---

--- file main.c ---
extern void mylib_init();
extern void mylib_free();

int main() {
        mylib_init();
        mylib_free();
        return 0;
}
---

I am compiling using:
$ dmd -c -lib mylib.d -oflibmylib.a
$ gcc -o main main.c -L. -lmylib -lphobos2

When I run ./main, I get a EXC_BAD_ACCESS (SIGSEGV) that seems related to thread local storage during runtime initialization.

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 main 0x0000000103072dac __tls_get_addr + 196 1 main 0x0000000103071d80 thread_attachThis + 312 2 main 0x0000000103071c3c thread_init + 24
3   main                                0x0000000103073296 gc_init + 86
4   main                                0x0000000103079f79 rt_init + 29
5 main 0x00000001030705bb D4core7runtime7Runtime10initializeFDFC6object9ThrowableZvZb + 15 6 main 0x0000000103069e5d mylib_init + 13
7   main                                0x0000000103069e2f main + 15
8   main                                0x0000000103069e14 start + 52

Am I doing something wrong or trying to do something currently unsupported?

Thanks,
Nicolas


Reply via email to