這段時間用到了scons,這里總結下,也方便我以后查閱。
一、安裝scons
Linux環境(以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 : 可以清除生成的臨時文件和目標文件,相當于執行make clean。
scons -Q : 將產生更少的輸出信息。
三、scons使用示例
1、編譯可執行文件
使用Program函數進行可執行文件的編譯。
1.1 單文件方式
1.1.1 編寫程序代碼
建立文件test.c,內容如下:
#include <stdio.h>
int main()
{
printf("Just a test!\n");
return 0;
}
1.1.2 編寫SConstruct代碼
內容如下:
Program("test1.c")
1.1.3 編譯程序
執行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代碼
內容如下:
Program('test', ['test1.c','test2.c'])
或者:
Program('test',Glob('*.c'))
1.2.3 編譯程序
執行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、編譯靜態庫
語法示例如下:
Library('libtest1',['test1.c'])
3、編譯動態庫
語法示例如下:
SharedLibrary('libtest1',['test1.c'])
三、其它
參考資料
(1) scons主頁:http://www.scons.org/
(2) scons文檔:http://www.scons.org/documentation.php