c语言 - 基本SCons示例抛出"不知道如何使文件目标'helloworld'错误



我试图按照本教程使用SCons构建一个简单的C程序。我创建了一个名为SConstruct的文件,其中包含以下内容:

env = Environment() # construction environment
env.Program(target='helloworld', source=['helloworld.c']) # build targets

我创建了一个名为helloworld.c的文件,其中包括以下内容:

#include <stdio.h>
int main() 
{
printf("Hello World.");
}

然后我尝试从Powershell构建如下:

scons helloworld

不幸的是,我得到了以下输出

scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
scons: building terminated because of errors.
scons: *** Do not know how to make File target `helloworld` (..scons-tutorialhelloworld). Stop.

我非常仔细地遵循了教程中的步骤,所以我不确定在这一点上我还能做什么。我在这里做错了什么?

错误消息是因为没有helloworld目标。是的,您说的是target='helloworld',但SCons使SConscript易于移植,并且假设前缀和后缀扩展是在构建期间添加的,此时可以解析平台。

这意味着在Windows上,PROGSUFFIX(程序后缀(是.exe,您应该键入scons helloworld.exe来构建目标。请注意,所有生成输出文件路径都是隐式目标。

如果您想使scons helloworld成为构建的平台可移植命令,可以使用别名:

helloworld_nodes = env.Program(target='helloworld', source=['helloworld.c']) # build targets
env.Alias('helloworld_app', helloworld_nodes)

现在,您可以在任何平台上键入scons helloworld_app,它将构建helloworld二进制文件。

事实证明,该链接第2.1节中的说明更准确。在SConstruct文件中有以下内容就足够了:

Program(target='helloworld', source='helloworld.c') # build targets

然后从命令行运行一个简单的scons

相关内容

最新更新