scons_SCons入门

scons

SCons is a next-generation make utility that is much easier to configure and use than make. Many developers find make syntax not just difficult to get into but quite ugly. Once you've learned it, it's okay, but it has a bit of a steepish learning curve.

SCons是下一代make实用程序,它比make易于配置和使用。 许多开发人员发现make语法不仅难以使用,而且非常难看。 一旦您了解了它,就可以了,但是学习曲线有些陡峭。

So that's why SCons was devised; it's a better make and considerably easier to use. It even tries to figure out what compiler is needed and then supplies the right parameters. If you program in C or C++ on Linux or Windows then you should definitely check SCons.

这就是设计SCons的原因。 这是一个更好的产品,而且使用起来也相当容易。 它甚至试图找出所需的编译器 ,然后提供正确的参数。 如果您在Linux或Windows上使用C或C ++进行编程,则一定要检查SCons。

安装 ( Installation )

To install SCons you need to have Python already installed. If you are using Linux then most likely you'll have Python already. If you have Windows you can check if you already have it; some packages might have installed it already. First, get a command line. Click the start button, (on XP click Run), then type cmd and from the command line type python -V. It should say something like Python 2.7.2. Any version 2.4 or higher is ok for SCons.

要安装SCons,您需要已安装Python 。 如果您使用的是Linux,那么很可能已经有了Python。 如果您使用Windows,则可以检查是否已经安装了Windows。 一些软件包可能已经安装了它。 首先,获取命令行。 单击开始按钮(在XP上单击“运行”),然后键入cmd并从命令行键入python -V。 它应该说类似Python 2.7.2。 SCons可以使用任何2.4或更高版本。

If you haven't got Python then you need to download and install 2.7.2. Currently, SCons does not support Python 3 so 2.7.2 is the latest (and final) 2 version and the best one to use. However, that may change in the future so check the SCons requirements.

如果您还没有Python,则需要下载并安装2.7.2。 当前, SCons不支持Python 3,因此2.7.2是最新的(也是最终的)2版本,也是最好的版本。 但是,将来可能会改变,因此请检查SCons要求

Follow the instructions for installing SCons. It's not complicated; however, when you run the installer, if it's under Vista/Windows 7 make sure you run the scons.win32.exe as administrator. You do this by browsing to the file in Windows Explorer and right click then Run As Administrator.

请按照说明安装SCons。 这并不复杂; 但是,如果在Vista / Windows 7下运行安装程序,请确保以管理员身份运行scons.win32.exe。 您可以通过在Windows资源管理器中浏览该文件并右键单击,然后以管理员身份运行来执行此操作。

Once it's installed then, assuming you have any of Microsoft Visual C++ (Express is ok), MinGW tool chain, Intel Compiler or the PharLap ETS compiler already installed, SCons should be able to find and use your compiler.

安装完成后,假设您已经安装了Microsoft Visual C ++(可以使用Express),MinGW工具链,Intel编译器或PharLap ETS编译器,则SCons应该能够找到并使用您的编译器。

使用SCons ( Using SCons )

As a first example, save the code below out as HelloWorld.c.

作为第一个示例,将下面的代码另存为HelloWorld.c。


int main(int arcg,char * argv[])
{
printf("Hello, world

Then create a file called SConstruct in the same location and edit it so it has this line below in it. If you save the HelloWorld.c with a different filename, make sure that the name inside the quotes matches.

然后在相同位置创建一个名为SConstruct的文件并对其进行编辑,以使该行位于下面。 如果使用其他文件名保存HelloWorld.c,请确保引号内的名称匹配。


Program('H

Now type scons at the command line (in the same place as HelloWorld.c and SConstruct) and you should see this:

现在,在命令行(与HelloWorld.c和SConstruct相同的位置)中键入scons,您应该看到以下内容:


C:\cplus\blog>scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
cl /FoHelloWorld.obj /c HelloWorld.c /nologo
HelloWorld.c
link /nologo /OUT:HelloWorld.exe HelloWorld.obj
scons: done

This built a HelloWorld.exe which when run produces the expected output:

这建立了一个HelloWorld.exe,运行时会产生预期的输出:


C:\cplus\blog>HelloWorld
 

Notes

The online documentation is very good for getting you started. You can refer to the terse single file man (manual) or the friendlier more verbose SCons Users Guide.

SCons makes it easy to remove unwanted files from the compilation just add the -c or -clean parameter.

This gets rid of HelloWorld.obj and the HelloWorld.exe file.

SCons is cross-platform, and while this article has been about getting started on Windows, SCons comes prepackaged for Red Hat(RPM) or Debian systems. If you have another flavor of Linux, then the SCons guide gives instructions for building SCons on any system. It's open source at its best.

SCons SConstruct files are Python scripts so if you know Python, then you'll have no probs. But even if you don't, you only need to learn a small amount of Python to get the best out of it. Two things you should remember, though:

  1. Comments start with #
  2. You can add print messages with print("Some Text")

Note that SCons is only for non-.NET, so it can't build .NET code unless you learn SCons a bit more and create a specific builder.

翻译自: https://www.thoughtco.com/getting-started-with-scons-958265

scons

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值