digitalmars.D.learn - Using D-object with C-executable
- stas (31/31) Mar 14 2013 Hi guys!
- Adam D. Ruppe (6/6) Mar 14 2013 gotta init the d runtime first
- stas (1/1) Mar 14 2013 Thanks Adam! You saved my day ;)
Hi guys! I'm trying to write D module for existing C/C++ project with no success :( What I'm doing: [code] dmd -g -w -c test.d gcc -g -Wall -Werror test.c test.o -ldruntime -lphobos2 -lrt -pthread -o test-app [/code] Executable is linked successfully, but fails with "Segmentation fault". test.d: [code] import std.stdio; extern(C) int this_is_test_d_function(const char* test_data) { writeln("Hello from C-called D!"); return false; } void main() {} [/code] test.c: [code] int this_is_test_d_function(const char* test_data); int main(int argc, char**argv) { this_is_test_d_function("test C line"); return 0; } [/code] Is it possible at all?
Mar 14 2013
gotta init the d runtime first extern (C) void startd() { Runtime.initialize(); } adn then in C, before using any other D, call startd();
Mar 14 2013