gpt4 book ai didi

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

转载 作者:太空狗 更新时间:2023-10-29 23:18:02 25 4
gpt4 key购买 nike

这是 my project在 github 上。

这是我的 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: 程序(target = 'main.bin', source = Glob('*.cpp'))

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

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

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

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

最佳答案

会不会是因为你的main.scons文件已经在src目录下了,而你的find_source_file其实是在搜索src/源?当我将 scons 文件移动到顶级目录时,它为我找到了源代码。

更新:经过调查,variant_dir 将工作目录设置为 build,因此您的 find_source_files 会在 build/src 中查找文件,并且什么也没找到。从 SConstruct 文件调用 find_source_files 或在 main.scons 中使用 VariantDir() 可能会更好。

关于c++ - 为什么scons找不到我项目的源文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15328995/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com