scons 简要说明
文章目录
写在前面
scons和make有什么不同
make中使用了目标和为伪目标相互依赖的方法将需要编译的项目和
依赖的目标链接起来。比如一个.bin文件依赖.o ,而.o文件依赖于
.s 或者.c。
对于编译项目,需要处理的基本问题就是如上的需求。
而scons的编译函数中都有一个编译目标 和编译来源的入参,因此scons
在编译过程中会自动推导依赖关系,而不用显示的去指明依赖链条.
scons 安装
pip install scons
scons 的基本使用
1. 编译单个文件和常用的操作介绍
- 如何编译一个单文件
1.1 比如现在需要编译一个main.cpp,在main.cpp所在目录执行下边命令
1.2 分析上边的过程Program函数是用来生成最终的执行目标,可以自动推导默认的编译方法编译出最终目标ggg@ggg-X550JX ~/test_demo/test_demo/pro1 $ echo Program\(\"main.cpp\"\) > Sconstruct ggg@ggg-X550JX ~/test_demo/test_demo/pro1 $ cat Sconstruct Program("main.cpp") ggg@ggg-X550JX ~/test_demo/test_demo/pro1 $ scons scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... g++ -o main.o -c main.cpp g++ -o main main.o scons: done building targets. ggg@ggg-X550JX ~/test_demo/test_demo/pro1 $ ls main main.cpp main.o Sconstruct
- 清理项目
2.1 清理命令是 scons -c
2.2 scons 上不用去专门编写项目的清理方法,scons会自动由最终结果往前的这个链条上所有中间文件,并删除掉ggg@ggg-X550JX ~/test_demo/test_demo/pro1 $ ls main main.cpp main.o Sconstruct ggg@ggg-X550JX ~/test_demo/test_demo/pro1 $ ggg@ggg-X550JX ~/test_demo/test_demo/pro1 $ scons -c scons: Reading SConscript files ... scons: done reading SConscript files. scons: Cleaning targets ... Removed main.o Removed main scons: done cleaning targets. ggg@ggg-X550JX ~/test_demo/test_demo/pro1 $ ls main.cpp Sconstruct
- 打印依赖树
ggg@ggg-X550JX ~/test_demo/test_demo/pro1 $ scons --tree=all scons: Reading SConscript files ... scons: done reading SConscript files. scons: Building targets ... g++ -o main.o -c main.cpp g++ -o main main.o +-. +-Sconstruct +-main | +-main.o | | +-main.cpp | | +-/usr/bin/g++ | +-/usr/bin/g++ +-main.cpp +-main.o +-main.cpp +-/usr/bin/g++ scons: done building targets.
- 静默编译
ggg@ggg-X550JX ~/test_demo/test_demo/pro1 $ scons -Q g++ -o main.o -c main.cpp g++ -o main main.o ggg@ggg-X550JX ~/test_demo/test_demo/pro1 $ scons -c -Q Removed main.o Removed main
- 为输出目标命名
ggg@ggg-X550JX ~/test_demo/test_demo/pro1 $ echo Program\(\