windows下c++调用d.

d代码:

import std.stdio;
extern(C++)void hi()
{
    writeln("hello");
}//还是必须utf8.
`

命令:ldc2 -lib b0.d
c++这边:

#include <iostream>
//#pragma comment(lib,"b0")
void hi();
extern "C" int rt_init();
extern "C" int rt_term();

void main() {
    std::cout << "你好"<<"\n";
  rt_init(); //必须加,不然要崩溃
    hi();
  rt_term(); // 终止
}

命令:!cl % b0.lib phobos2-ldc.lib druntime-ldc.lib
ldc2没问题.dmdphobosm32coff.lib中还缺少些文件.不行.
这样是可以调用的.

posted @ 2020-09-24 09:18  zjh6  阅读(20)  评论(0)    收藏  举报  来源