使用SCons进行编译时找不到编译器

时间:2020-04-11 23:19:49

标签: bash sh ubuntu-18.04 scons

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

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

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

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

1 个答案:

答案 0 :(得分:0)

由于没有提供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.
相关问题