D static lib called from C on Mac OS X

Nicolas Sicard dransic at gmail.com
Wed Apr 25 10:18:15 PDT 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.




More information about the Digitalmars-d-learn mailing list