随想录(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还要简单。

 

 

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