为什么scons找不到我项目的源文件?

时间:2013-03-10 23:23:16

标签: c++ scons

这是github上的my project

这是我的SConstruct文件:

SConscript('main.scons', variant_dir = 'build', duplicate = 0)

这是我的main.scons文件:

import sys
import os
import fnmatch

def find_source_files(directory, ext = "cpp"):
    matches = []
    for root, dirnames, filenames in os.walk(directory):
      for filename in fnmatch.filter(filenames, '*.' + ext):
          matches.append(os.path.join(root, filename))
    return matches

if __name__ == '__main__':
    for f in find_source_files('src'):
        print f
else: 
    Program(target = 'main.bin', source = find_source_files('src'))

这是我运行时得到的结果:

bitcycle @ cypher ~/git/IeiuniumTela $ find $(pwd) -name "*.bin" -or -name "*.o" -exec rm {} \;;  scons; find $(pwd) -name "*.bin" -or -name "*.o"

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: building associated VariantDir targets: build
gcc -o build/main.bin
gcc: fatal error: no input files
compilation terminated.
scons: *** [build/main.bin] Error 4
scons: building terminated because of errors.

当我运行`python main.scons'来测试它时会发生什么:

bitcycle @ cypher ~/git/IeiuniumTela $ python main.scons
src/main.cpp

我很难理解为什么找不到我的源文件。这里有任何建议或想法吗?

[更新] 在从邮件列表中获得一些好的指示后,我发现这对我来说“足够好”。

/ SConstruct SConscript('src/main.scons', variant_dir = 'build', duplicate = 0)

/src/main.scons Program(target = 'main.bin', source = Glob('*.cpp'))

请参阅github存储库以获取完整的源代码树。为了完整性,我还在repo中添加了一个空的构建目录。我觉得它很感兴趣:

一个。在用于发现源的构建工具的上下文中,SCons的Glob版本不是递归的。我希望首选递归发现选项。 :(

湾我需要将scons文件放在与源文件相同的目录中(这很烦人)。

℃。打印语句显然有效,但sys.stdout.write没有(来自python模块)。

2 个答案:

答案 0 :(得分:0)

可能是因为您的main.scons文件已经在src目录中,而您的find_source_file实际上正在搜索src/src吗? 当我将scons文件移动到顶层目录时,它找到了源代码。

<强>更新 经过调查,variant_dir将工作目录设置为build,因此您的find_source_files会在build/src中查找文件,但一无所获。最好从SConstruct文件中调用find_source_files,或者在main.scons中使用VariantDir()

答案 1 :(得分:0)

SCons以不同于Python的方式处理相对目录路径,因此我不会惊讶地发现测试执行与SCons执行之间存在差异。通常在SCons中,所有内容都与根SConstruct脚本或SConscript脚本相关。

您的代码显示正确,但如何在find_source_files()中添加一些调试打印语句以确切了解发生了什么?

也许您计划稍后更广泛地使用find_source_files()函数,但对于一个源文件的简单情况,您似乎已经过度复杂化了,您可以在{{1}中使用以下内容}:

main.scons