Macos Scons不在OSX中构建简单的D程序

Macos Scons不在OSX中构建简单的D程序,macos,d,scons,Macos,D,Scons,当我尝试使用SCON构建一个简单的D文件时,我遇到了一个错误。我已经通过构建一个简单的helloworld.c测试了SCON,但是D中的等价物并没有出现,我对SCON还不够聪明,不知道这是一个bug还是我的设置有问题 我返回的错误是ld:library找不到-lphobos 我的SConstruct文件: SConscript('SConscript', variant_dir='release', duplicate=0, exports={'MODE':'release'}) SConscr

当我尝试使用SCON构建一个简单的D文件时,我遇到了一个错误。我已经通过构建一个简单的helloworld.c测试了SCON,但是D中的等价物并没有出现,我对SCON还不够聪明,不知道这是一个bug还是我的设置有问题

我返回的错误是
ld:library找不到-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
二进制dmd
版本v2.058
config/usr/bin/dmd.conf
解析你好
你好
...  ...
代码你好
功能D主
函数std.stdio.writeln!(字符串).writeln
函数std.stdio.writeln!(字符串).writeln.u dLiteral834
函数std.exception.exforce!(bool,“/usr/share/dmd/src/phobos/std/stdio.d”,1550)。强制执行
gcc hello.o-o hello-m64-Xlinker-L/usr/share/dmd/lib-lphobos2-lpthread-lm

请注意,我必须在编译器上启用详细性才能让它显示任何内容。正常情况下,它会以静默方式构建并链接文件。

在通过注释了解输出告诉我的内容后,我对配置文件进行了更多的操作,并得到了我想要的结果。我觉得这是一个变通办法,在某种程度上破坏了SCons所追求的“巡航控制”功能,但我有一个构建,所以我不能抱怨

我不得不修改我的SConscript文件,使其看起来像这样:

env = Environment()
target       = 'helloworld'
sources      = ['hello.d']
libraries    = ['phobos2', 'pthread', 'm']
libraryPaths = ['/usr/share/dmd/lib', 
                '/usr/share/dmd/src/druntime/import', 
                '/usr/share/dmd/src/phobos']

env.Program(target = target, 
            source = sources,
            LIBS = libraries,
            LIBPATH = libraryPaths)

这里的关键变化是增加了LIBS,并明确地写出要包含哪些库,而不是依赖scon来确定。不幸的是,当您添加一个时,您必须显式地链接它们。尽管如此,希望这能帮助其他想要快速运行D和SCON的人。

您能展示SCON输出(生成的编译器命令)并展示如何“手工”编译相同的命令吗。指定库路径似乎是一个简单的问题,但我对D的了解还不够,不知道这是否是D标准运行时库所必需的。我已经更新了有关您问题的问题,在进行详细构建时,我突然发现了一个问题:DMD正在链接
-lphobos2
,而scons似乎在寻找
-lphobos
。DMD.py似乎知道phobos2是存在的,所以我不确定它为什么会这样链接。总体而言,您对SCons作为D的构建工具感到满意吗?在另一个项目出现时,还没有使用它一整吨,但我对SCons总体上很满意。我将强烈地考虑到我需要构建的任何控制项目,尽管它对于D工作得很好,但肯定比D.@ CodexArcanum所发现的任何东西都要好。
env = Environment()
target       = 'helloworld'
sources      = ['hello.d']
libraries    = ['phobos2', 'pthread', 'm']
libraryPaths = ['/usr/share/dmd/lib', 
                '/usr/share/dmd/src/druntime/import', 
                '/usr/share/dmd/src/phobos']

env.Program(target = target, 
            source = sources,
            LIBS = libraries,
            LIBPATH = libraryPaths)