---
title: "SCons上手"
author: "fkpwolf"
date: "2011-09-29T16:18:02Z"
tags: []
categories: ["编程语言"]
slug: "scons"
draft: false
lastmod: "2011-10-10T15:27:00Z"
id: 1183318
url: "https://fkpwolf.iteye.com/blog/1183318"
---

参考这篇文章：[使用 SCons 轻松建造程序](http://www.ibm.com/developerworks/cn/linux/l-cn-scons/index.html)。

 

如果想看环境，比如使用的C++编译器，使用如下的SConstruct：

 

 

```
env = Environment()
print env.Dump('ENV')
Program('a.c') 
```

 

我的机器上输出如下：

 

 

```
C:\dev\cygwin\home\fan\helloscons>scons
scons: Reading SConscript files ...
{ 'COMSPEC': 'C:\\WINDOWS\\system32\\cmd.exe',
  'INCLUDE': 'c:\\Program Files\\Microsoft Visual Studio 10.0\\VC\\INCLUDE;C:\\P
rogram Files\\Microsoft SDKs\\Windows\\v7.0A\\include',
  'LIB': 'c:\\Program Files\\Microsoft Visual Studio 10.0\\VC\\LIB;C:\\Program F
iles\\Microsoft SDKs\\Windows\\v7.0A\\lib',
```

 

Scons可以自动检测到系统中常见的编译器，上面这个是VS 10 express版本，当然如果Scons太旧或者Compiler太新可能有点问题。看上去是比make简单，但是也要写代码啊，不过好歹Python容易懂点。

 

不知道这东东和IDE结合的怎么样，比如xcode本来就是一个很好的c/c++ ide，但是有自己的一套build系统。如果一个project中有两个带main的c文件，build的时候failed，这个就不够智能，也有可能是我还需要配置xcode。当然，如果能和scons结合就好了。