Hi, I'm a new to D and I could not find any relevant answers in the forum.

I want to call functions from D-lib from c++ main.
dlibrary

import std.stdio;

extern (C++) void foo(int i, int j, int k) {
  writefln("i = %s", i);
  writefln("j = %s", j);
  writefln("k = %s", k);
}
void main(){}

######
c++ binary

#include <iostream>

void CXXmain();
void foo(int i, int j, int k);
using namespace std;

int main(){
  cout << "This is the main of C++\n";
  foo(1,3,4);
  return 0;
}

####
I can compile d with dmd and c++ with g++ then linked them with g++. The problem is when I run the binary I got:

./runtest
This is the main of C++
Segmentation Fault

I could not figure out the problem. And when I call the C++ functions from the main of D everything works. So why have I segmentation when I call the main from C++.



Reply via email to