How to link to D Libraries in a D program

一世执手 提交于 2019-12-05 03:42:42

there are .di (D interface) files which can be used as header these can be generated from your sources with the -H compiler switch

however the libraries I've seen will just have the source files to import

you can use the -I switch to specify where the compiler will look for imports

and the -L switch will be passed to the linker

dnewbie

Create StaticLib.d:

module StaticLib;

int func(int x)
{
    return x+1;
}

Compile it:

dmd -lib StaticLib.d -ofStaticLib.lib

Create App.d:

module App;
import std.stdio;
import StaticLib;

void main(string[] args)
{
    writeln("func(3) = ", StaticLib.func(3));
}

Create StaticLib.di (d header):

int func(int x);

Compile it:

dmd App.d StaticLib.di StaticLib.lib -ofApp.exe
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!