digitalmars.D.learn - D static lib called from C on Mac OS X
- Nicolas Sicard (49/49) Apr 25 2012 Hi,
- Nicolas Sicard (1/1) Apr 25 2012 s/void/int in main.c
- Nicolas Sicard (34/34) Apr 25 2012 More testing. This:
- Andrej Mitrovic (2/5) Apr 25 2012 Try changing void to bool there.
- Nicolas Sicard (4/9) Apr 25 2012 This was a typo in my first post. The problem is elsewhere.
- Nicolas Sicard (1/1) Apr 27 2012 Bug report: http://d.puremagic.com/issues/show_bug.cgi?id=7995
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
Apr 25 2012
More testing. This: --- file mylib.d module mylib; import core.runtime; import std.stdio; extern(C) { bool mylib_init() { return Runtime.initialize(); } bool mylib_free() { return Runtime.terminate(); } void mylib_hello() { writeln("Hello from mylib"); } } void main() {} // Fake main --- --- file main.c --- extern int mylib_init(); extern int mylib_free(); extern void mylib_hello(); int main() { mylib_init(); mylib_hello(); mylib_free(); return 0; } --- $ dmd -c mylib.d $ gcc -o main main.c mylib.o -lphobos2 -lpthread -lrt $ ./main works on Linux (Unbuntu 11.10), but segfaults on OS X Lion.
Apr 25 2012
On 4/25/12, Nicolas Sicard <dransic gmail.com> wrote:--- file main.c --- extern void mylib_init(); extern void mylib_free();Try changing void to bool there.
Apr 25 2012
On Wednesday, 25 April 2012 at 17:59:38 UTC, Andrej Mitrovic wrote:On 4/25/12, Nicolas Sicard <dransic gmail.com> wrote:This was a typo in my first post. The problem is elsewhere. Thanks--- file main.c --- extern void mylib_init(); extern void mylib_free();Try changing void to bool there.
Apr 25 2012
Bug report: http://d.puremagic.com/issues/show_bug.cgi?id=7995
Apr 27 2012