| Thread overview | |||||
|---|---|---|---|---|---|
|
March 14, 2013 Using D-object with C-executable | ||||
|---|---|---|---|---|
| ||||
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?
| ||||
March 14, 2013 Re: Using D-object with C-executable | ||||
|---|---|---|---|---|
| ||||
Posted in reply to stas | gotta init the d runtime first
extern (C)
void startd() {
Runtime.initialize();
}
adn then in C, before using any other D, call startd();
| |||
March 14, 2013 Re: Using D-object with C-executable | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Adam D. Ruppe | Thanks Adam! You saved my day ;) | |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply