次の2つのファイルをリンクすると、リンクエラーが発生します。
広告:
import std.stdio;
extern string test ();
void main() {
writeln(test());
readln();
}
bd:
string test () {
return "hello";
}
私が得るエラーは次のとおりです。
Error 42: Symbol Undefined _D1a4testFZAya`
---errorlevel 1
なにが問題ですか ?
__ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ __ _ _
編集:これはそれを行う正しい方法です:
広告:
import std.stdio;
import b;
void main() {
writeln("some_var from Module b: \"", b.some_var, "\"");
}
bd:
public string some_var = "Hello, world!";
//you can also use static module constructors to set your vars
static this() {
some_var ~= " -- How are you?";
}
そのコードは、digitalmars.comサイトの初心者向けの優れたDフォーラムでJoshuaReuschから提供されました。