Linking C++ with a D-library

Adam D. Ruppe destructionator at gmail.com
Wed Jun 26 13:23:34 PDT 2013


On Wednesday, 26 June 2013 at 20:19:07 UTC, Milvakili wrote:
> 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(){}


Try adding this to D:

extern(C) void initialize_D() {
   import core.runtime;
   Runtime.initialize();
}



And this to C++:

> void foo(int i, int j, int k);

extern "C" void initialize_d();

> using namespace std;
>
> int main(){

     initialize_d();

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


And you should see something better.


More information about the Digitalmars-d mailing list