【问题标题】:SCons does not find file it should build itselfSCons 没有找到它应该自己构建的文件
【发布时间】:2018-03-13 03:20:15
【问题描述】:

我有一个简单的 SConstruct 文件来使用 MinGW 构建 google 测试库:

env = Environment(platform='posix')  # necessary to use gcc and not MS
env.Append(CPPPATH=['googletest/'])
env.Append(CCFLAGS=[('-isystem', 'googletest/include/'), '-pthread'])
obj = env.Object(source='googletest/src/gtest-all.cc')
# linking skipped due to error search
# env.Append(LINKFLAGS=['-rv'])
# bin = env.StaticLibrary(target='libgtest', source=[obj])

脚本位于主 googletest\ 文件夹中。运行它时——不管有没有链接——输出是这样的:

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
g++ -o googletest\src\gtest-all.o -c -isystem googletest/include/ -pthread -Igoogletest googletest\src\gtest-all.cc
scons: *** [googletest\src\gtest-all.o] The system cannot find the file specified
+-.
  +-googletest
  | +-googletest\src
  |   +-googletest\src\gtest-all.cc
  |   +-googletest\src\gtest-all.o
  |   | +-googletest\src\gtest-all.cc
  |   | +-googletest\src\gtest-death-test.cc
  |   | +-googletest\src\gtest-filepath.cc
  |   | +-googletest\src\gtest-port.cc
  |   | +-googletest\src\gtest-printers.cc
  |   | +-googletest\src\gtest-test-part.cc
  |   | +-googletest\src\gtest-typed-test.cc
  |   | +-googletest\src\gtest.cc
  |   | +-googletest\src\gtest-internal-inl.h
  |   +-googletest\src\gtest-death-test.cc
  |   +-googletest\src\gtest-filepath.cc
  |   +-googletest\src\gtest-internal-inl.h
  |   +-googletest\src\gtest-port.cc
  |   +-googletest\src\gtest-printers.cc
  |   +-googletest\src\gtest-test-part.cc
  |   +-googletest\src\gtest-typed-test.cc
  |   +-googletest\src\gtest.cc
  |   +-googletest\src\libgtest-all.a
  |     +-googletest\src\gtest-all.o
  |       +-googletest\src\gtest-all.cc
  |       +-googletest\src\gtest-death-test.cc
  |       +-googletest\src\gtest-filepath.cc
  |       +-googletest\src\gtest-port.cc
  |       +-googletest\src\gtest-printers.cc
  |       +-googletest\src\gtest-test-part.cc
  |       +-googletest\src\gtest-typed-test.cc
  |       +-googletest\src\gtest.cc
  |       +-googletest\src\gtest-internal-inl.h
  +-SConstruct
scons: building terminated because of errors.

我也尝试在一行中构建库:env.StaticLibrary(source='googletest/src/gtest-all.cc') - 结果是一样的。

只需执行实际的 g++ 调用就可以得到我想要的目标文件。 让我感到困惑的是,SCons 应该将目标文件视为它自己创建的工件。我想知道为什么它会在完成之前尝试使用它。那么我在这里错过了什么?如何让 SCons 等到编译完成?

顺便说一句:我只是在使用 SCons 方面有一些经验,并且偶尔会调整一个脚本 - 但我对它并没有深入的了解。

使用的版本:SCons 3.0.1、Python 3.6.3、MinGW 7.3.0

【问题讨论】:

  • 你能告诉我们“scons --tree=all”的输出吗?

标签: scons


【解决方案1】:

这行得通吗?

env = Environment(tools=['mingw','gnulink','ar'])  # You should specify the tools
env.Append(CPPPATH=['googletest/'])
env.Append(CCFLAGS=[('-isystem', 'googletest/include/'), '-pthread'])
obj = env.Object(source='googletest/src/gtest-all.cc')
# linking skipped due to error search
# env.Append(LINKFLAGS=['-rv'])
# bin = env.StaticLibrary(target='libgtest', source=[obj])

【讨论】:

  • 确实,在我阅读了PATH (Environment(ENV = {'PATH' : os.environ['PATH']}, tools=['mingw','gnulink','ar'])) 之后,它确实有效。阅读PATH 并没有改变我最初的尝试。那么,我能从中得到什么? platform=posix 只是没有像我想象的那样在 WINdows 上选择 gcc 工具集?
  • 没有。 Posix 表示您在 posix 系统上。 Windows 不是这样的。如果您不想使用 SCons 的默认设置,则需要单独选择工具。顺便说一句.. mingw 安装的路径是什么?尝试改进此类的默认搜索路径。
  • 您是否在某处看到建议将平台设置为 posix 的文件或网页?
  • 不,那是我自己的想法。我只是想否决默认的 Windows 工具链。我的 MINGW 的路径就像 C:\MinGW\bin 并导出为环境变量。我现在用的是哪个,而不是 unspecific%PATH%
  • 顺便说一句:是的,设置 platform='posix' 是 - 可以说 - 非常乐观。虽然我还是不明白,为什么这让 scons 迫不及待地完成文件。我什至没有想到这可能是问题所在。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-02-06
  • 2019-07-24
  • 1970-01-01
  • 1970-01-01
  • 2011-08-22
  • 2021-06-05
相关资源
最近更新 更多