d,ldc构建共享库

原文

module dimedll;

export void testFunc() { // 仅用`-fvisibility=hidden`编译时,需要export
    import std.stdio;
    writeln("This is from dll");
}

ldc2 -shared dimedll.d生成lib/dll.

import dimedll : testFunc;

pragma(lib, "dimedll");

void main() {
    import std.stdio;
    writeln("构建ime");
    testFunc();
}

ldc2 -link-defaultlib-shared dime.d生成带dimedll.dllexe
Posix中区别是,不是用pragma(lib),你要用-L-ldimedll链接至libdimedll.{so,dylib}.

posted @ 2022-07-02 23:27  zjh6  阅读(16)  评论(0)    收藏  举报  来源