【问题标题】:Compiler not found when building with SCons使用 SCons 构建时找不到编译器
【发布时间】:2020-04-11 23:19:49
【问题描述】:

我正在尝试使用我将称为“comp”的编译器(位于 ~/code/myComp/bin/ 在 Ubuntu 18.04 上使用 SCons 来构建文件“file.ext”。我收到一条错误消息说-

        comp file.ext -o file.out
        sh: 1: comp: not found
        scons: *** [file.out] Error 127
        scons: building terminated because of errors.

但是,当我将完全相同的构建行复制并粘贴到终端时,会找到编译器并且构建成功且没有问题。 SCons 环境具有系统 PATH 的正确值 - 我通过使用 os.environ['PATH'] 显式复制外部环境中的值并将值传递给 Environment 构造函数来在构造环境中设置 PATH。

我使用 /bin/bash 创建我的构建环境,并提供一个小的 shell 脚本来定义编译器所在的位置等...... 我想知道这是否与使用 /bin/sh 的 SCons 有任何关系,即内部使用 dash 而不是 /bin/bash。任何帮助将不胜感激。

【问题讨论】:

  • 通常第 1 行的“未找到”错误意味着找不到 shell 解释器。我无法想象您的设置。您能否提供更多详细信息(SConstruct、构建环境脚本、comp)?
  • comp 是二进制文件还是 shell 脚本?
  • 如果您提供 SCons 的完整路径以进行 comp,它是否有效?
  • comp 是二进制文件。
  • 如果我在 SCon 中提供 comp 的完整路径,它可以正常工作。

标签: bash sh ubuntu-18.04 scons


【解决方案1】:

由于没有提供Minimal Reproducible Example,我将只向您展示一个工作示例,也许您可​​以比较一下您的环境是如何设置的。

这是一个 SConstruct 示例:

import os, stat

# arbitrary location for fake compiler
f = open("/tmp/comp.sh", "w")
f.write("""echo "COMPILER COMPILING!"
cat $1 > out.ext
echo " is compiled" >> out.ext""")
f.close()

# make sure its executable
os.chmod("/tmp/comp.sh", stat.S_IRWXU) 

# fake input file
f = open("out.in", "w")
f.write("code")
f.close()

# add arbitrary path to environment
os.environ['PATH'] = os.environ['PATH'] + ":/tmp"

env = Environment(ENV = os.environ)
#env = Environment() # not setting the ENV causes sh: 1: comp.sh: not found
env.Command('out.ext', 'out.in', 'comp.sh $SOURCE')

如果我使用 env = Environment(ENV = os.environ) 行,我得到的输出如下

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
comp.sh out.in
COMPILER COMPILING!
scons: done building targets.

如果我取消注释并使用env = Environment() 行并注释掉上一行,我得到的输出如下

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
comp.sh out.in
sh: 1: comp.sh: not found
scons: *** [out.ext] Error 127
scons: building terminated because of errors.

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多