【问题标题】:Scons not building simple D program in OSXScons 不在 OSX 中构建简单的 D 程序
【发布时间】: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 存在,所以我不确定它为什么以这种方式链接它。

标签: macos d scons


【解决方案1】:

在通过评论意识到输出告诉我的内容后,我对配置文件进行了更多尝试,并得到了我想要的结果。我觉得这是一种解决方法,它在某种程度上破坏了 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 并明确写出要包含的库,而不是依赖 SCons 来解决。不幸的是,当您添加一个时,您必须明确地将它们全部链接起来。尽管如此,希望这可以帮助任何想要快速使用 D 和 SCons 的人。

【讨论】:

  • 总的来说,您对 SCons 作为 D 的构建工具是否满意?
  • 当另一个项目出现时,我还没有完全使用它,但我对 Scons 总体上非常满意。对于我需要构建控制的任何项目,我都会强烈考虑使用它,尽管它对 D 来说效果很好。当然比我为 D 找到的任何其他项目都要好。
  • @CodexArcanum 有 Dub 构建系统/包管理器
猜你喜欢
  • 2014-02-26
  • 1970-01-01
  • 2016-07-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2010-12-08
  • 2013-06-24
  • 1970-01-01
相关资源
最近更新 更多