Python自動化構(gòu)建工具scons使用入門筆記
這段時間用到了scons,這里總結(jié)下,也方便我以后查閱。
一、安裝scons
Linux環(huán)境(以CentOS為例)
1、yum安裝
yum install scons
2、源碼安裝
下載scons:http://http://jaist.dl.sourceforge.net/project/scons/scons/2.3.0/scons-2.3.0.zip
安裝scons:python setup.py install
二、scons常用命令
scons -c : 可以清除生成的臨時文件和目標文件,相當于執(zhí)行make clean。
scons -Q : 將產(chǎn)生更少的輸出信息。
三、scons使用示例
1、編譯可執(zhí)行文件
使用Program函數(shù)進行可執(zhí)行文件的編譯。
1.1 單文件方式
1.1.1 編寫程序代碼
建立文件test.c,內(nèi)容如下:
#include <stdio.h>
int main()
{
printf("Just a test!\n");
return 0;
}
1.1.2 編寫SConstruct代碼
內(nèi)容如下:
Program("test1.c")
1.1.3 編譯程序
執(zhí)行scons命令進行編譯,效果如下:

1.2 多文件方式
1.2.1 編寫程序代碼
test1.h文件:
#include <stdio.h>
void fun11();
test1.c文件:
#include "test1.h"
void fun11()
{
printf("fun11\n");
}
test2.c文件:
#include "test1.h"
int main()
{
fun11();
return 0;
}
1.2.2 編寫SConstruct代碼
內(nèi)容如下:
Program('test', ['test1.c','test2.c'])
或者:
Program('test',Glob('*.c'))
1.2.3 編譯程序
執(zhí)行scons命令進行編譯。
1.3 依賴
1.3.1 鏈接庫
語法示例如下:
Program('test', ['test1.cpp'],LIBS=['boost_system','boost_thread-mt'], LIBPATH='/usr/lib64')
1.3.2 包含庫
語法示例如下:
Program('program',Glob('*.c'),CPPPATH='/home/admin/inc')
2、編譯靜態(tài)庫
語法示例如下:
Library('libtest1',['test1.c'])
3、編譯動態(tài)庫
語法示例如下:
SharedLibrary('libtest1',['test1.c'])
三、其它
參考資料
(1) scons主頁:http://www.scons.org/
(2) scons文檔:http://www.scons.org/documentation.php
相關(guān)文章
詳解Python常用標準庫之時間模塊time和datetime
從0編寫區(qū)塊鏈之用python解釋區(qū)塊鏈最基本原理
用python打包exe應(yīng)用程序及PyInstaller安裝方式

