隨想錄(scons編譯)

【 聲明:版權所有,歡迎轉載,請勿用於商業用途。  聯繫信箱:feixiaoxing @163.com】

 

    scons是基於python的一種編譯方法。所有編譯腳本的編寫,和編寫python腳本是一樣的。除了本身的邏輯非常簡單之外,用戶還可以在編譯代碼的同時,利用python腳本處理很多額外的工作,比如代碼搬家、merge、生成image等等。

 

1、安裝scons

shell> sudo apt-get install scons

 

2、確認scons安裝正確

shell> scons --help

 

3、編寫編譯腳本

Program("test.c")

 

4、編寫test.c代碼內容


#include <stdio.h>

int main(int argc, char* argv[])
{
    printf("%s\n", "hello world");
    return 0;
}

 

5、開始編譯

shell:~/Desktop$ scons
scons: Reading SConscript files ...
scons: done reading SConscript files.
scons: Building targets ...
gcc -o test.o -c test.c
gcc -o test test.o
scons: done building targets.

 

6、執行文件

shell:~/Desktop$ ./test
hello world

 

其他:

    除了單文件之外,scons還支持多文件編譯、靜態庫編譯、動態庫編譯、編譯選項添加、頭文件路徑添加、庫文件位置添加等多重操作。當然,你還可以利用python自身的語法來添加其他動作,總體來講,scons還是非常方便的。  如果和cmake相比較,感覺比cmake還要簡單。

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章