【发布时间】:2012-03-28 06:05:56
【问题描述】:
当我尝试使用 Scons 构建一个简单的 D 文件时出现错误。我已经通过构建一个简单的 helloworld.c 测试了 scons,但 D 中的等价物并没有发生,而且我对 Scons 不够聪明,无法知道这是我的设置的错误还是问题。
我返回的错误是ld: library not found for -lphobos
我的 SConstruct 文件:
SConscript('SConscript', variant_dir='release', duplicate=0, exports={'MODE':'release'})
SConscript('SConscript', variant_dir='debug', duplicate=0, exports={'MODE':'debug'})
我的 SConscript 文件:
env = Environment()
env.Program(target = 'helloworld',
source = ['hello.d'])
你好.d
import std.stdio;
void main() {
writeln("Hello, world!");
}
编辑:
完整的 scons 输出为:
MyComputer:thedbook me$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: release debug
gcc -o debug/helloworld debug/hello.o -L/usr/share/dmd/lib -L/usr/share/dmd/src/druntime/import -L/usr/share/dmd/src/phobos -lphobos -lpthread -lm
ld: library not found for -lphobos
collect2: ld returned 1 exit status
scons: *** [debug/helloworld] Error 1
scons: building terminated because of errors.
我感到困惑的原因是通常构建文件非常简单(这是一个文件 helloworld 案例):
$ dmd hello.d -v
binary dmd
version v2.058
config /usr/bin/dmd.conf
parse hello
importall hello
... <significant amount of imports here> ...
code hello
function D main
function std.stdio.writeln!(string).writeln
function std.stdio.writeln!(string).writeln.__dgliteral834
function std.exception.enforce!(bool,"/usr/share/dmd/src/phobos/std/stdio.d",1550).enforce
gcc hello.o -o hello -m64 -Xlinker -L/usr/share/dmd/lib -lphobos2 -lpthread -lm
请注意,我必须在编译器上启用详细程度才能让它显示任何内容。通常它会默默地构建和链接文件。
【问题讨论】:
-
您能否显示 SCons 输出(生成的编译器命令)并显示如何“手动”编译相同的内容。指定库路径似乎是一个简单的问题,但我对 D 的了解不够,无法知道 D 标准运行时库是否需要这样做。
-
我已经更新了关于您的问题的问题,并且在进行详细构建时突然出现了一些问题:DMD 正在链接
-lphobos2,而 scons 似乎正在寻找-lphobos. DMD.py 似乎知道 phobos2 存在,所以我不确定它为什么以这种方式链接它。