Using D-object with C-executable

stas stas at onlineua.net
Thu Mar 14 07:47:21 PDT 2013


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?


More information about the Digitalmars-d-learn mailing list