1 问题来源 本问题来源于rt-thread的技术论坛的一个常见问题,当时我回答了这个问题,很荣幸拿了一个最佳答案,为了能够再次消化并进行知识点沉淀,我把这个问题再次抛到这里。 原问题,请戳这里:scons 命令buildlib使用方法
2 实践分析 2.1 不懂就要问 既然不知道怎么用scons,那么我们先看到它的帮助信息,以下命令在scons的主目录执行,即可以找到sconscript的目录下执行:
rt-thread/bsp/qemu-vexpress-a9$ scons -h scons: reading sconscript files ... drivers/sconscript applications/sconscript [, , ] scons: done reading sconscript files. usage: scons [option] [target] ... scons options: -b, -d, -e, -m, -s, -t, -w, --environment-overrides, --no-keep-going, --no-print-directory, --print-directory, --stop, --touch ignored for compatibility. -c, --clean, --remove remove specified targets and dependencies. -c dir, --directory=dir change to dir before doing anything. --cache-debug=file print cachedir debug info to file. --cache-disable, --no-cache do not retrieve built targets from cachedir. --cache-force, --cache-populate copy already-built targets into the cachedir. --cache-readonly do not update cachedir with built targets. --cache-show print build actions for files from cachedir. --config=mode controls configure subsystem: auto, force, cache. -d search up directory tree for sconstruct, build all default() targets. --debug=type print various types of debugging information: count, duplicate, explain, findlibs, includes, memoizer, memory, objects, pdb, prepare, presub, stacktrace, time, action-timestamps. --diskcheck=type enable specific on-disk checks. --duplicate=duplicate set the preferred duplication methods. must be one of hard-soft-copy, soft-hard-copy, hard-copy, soft-copy, copy --enable-virtualenv import certain virtualenv variables to scons -f file, --file=file, --makefile=file, --sconstruct=file read file as the top-level sconstruct file. -h, --help print defined help message, or this one. -h, --help-options print this message and exit. -i, --ignore-errors ignore errors from build actions. -i dir, --include-dir=dir search dir for imported python modules. --ignore-virtualenv do not import virtualenv variables to scons --implicit-cache cache implicit dependencies --implicit-deps-changed ignore cached implicit dependencies. --implicit-deps-unchanged ignore changes in implicit dependencies. --interact, --interactive run in interactive mode. -j n, --jobs=n allow n jobs at once. -k, --keep-going keep going when a target can't be made. --max-drift=n set maximum system clock drift to n seconds. --md5-chunksize=n set chunk-size for md5 signature computation to n kilobytes. -n, --no-exec, --just-print, --dry-run, --recon don't build; just print commands. --no-site-dir don't search or use the usual site_scons dir. --profile=file profile scons and put results in file. -q, --question don't build; exit status says if up to date. -q suppress reading/building progress messages. --random build dependencies in random order. -s, --silent, --quiet don't print commands. --site-dir=dir use dir instead of the usual site_scons dir. --stack-size=n set the stack size of the threads used to run jobs to n kilobytes. --taskmastertrace=file trace node evaluation to file. --tree=options print a dependency tree in various formats: all, derived, prune, status, linedraw. -u, --up, --search-up search up directory tree for sconstruct, build targets at or below current directory. -u search up directory tree for sconstruct, build default() targets from local sconscript. -v, --version print the scons version number and exit. --warn=warning-spec, --warning=warning-spec enable or disable warnings. -y repository, --repository=repository, --srcdir=repository search repository for source and target files. local options: --dist make distribution --dist-strip make distribution and strip useless files --dist-ide make distribution for rt-thread studio ide --project-path=project-path set dist-ide project output path --project-name=project-name set project name --reset-project-config reset the project configurations to default --cscope build cscope cross reference database. requires cscope installed. --clang-analyzer perform static analyze with clang-analyzer. requires clang installed. it is recommended to use with scan-build like this: `scan-build scons --clang-analyzer` if things goes well, scan-build will instruct you to invoke scan-view. --buildlib=buildlib building library of a component --cleanlib clean up the library by --buildlib --target=target set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/ cdk/ses/makefile/eclipse/codelite/cmake --stackanalysis thread stack static analysis --genconfig generate .config from rtconfig.h --useconfig=useconfig make rtconfig.h from config file. --verbose print verbose information during build --menuconfig make menuconfig for rt-thread bsp --pyconfig python gui menuconfig for rt-thread bsp --pyconfig-silent don`t show pyconfig window 精准匹配下:
rt-thread/bsp/qemu-vexpress-a9$ scons -h | grep buildlib --buildlib=buildlib building library of a component --cleanlib clean up the library by --buildlib 2.2 实践出整理 从上面的帮助信息,我们已经找到关键信息了,我们来实践下:
rt-thread/bsp/qemu-vexpress-a9$ scons --buildlib=buildlib scons: reading sconscript files ... b'' drivers/sconscript applications/sconscript [, , ] scons: done reading sconscript files. scons: building targets ... scons: building associated variantdir targets: build scons: `.' is up to date. scons: done building targets. 发现并没有生成,仔细一看,这个buildlib=后面跟的名称不是乱填的,是需要填写你当前目录下,已经使用scons语法配置好的组件,这个东西在scons里面是叫group。 通俗来说,就是使用buildlib,一个gourp就可以生成一个库。 我们再来实践下,以bsp/qemu-vexpress-a9的application这个group为例,在其applications目录有定义sconsript:
那么就可以输入scons--buildlib=applications
就可以将applications那个group定义的c文件编译打包成一个静态库,输出也是位于bsp的目录中。
3 经验总结 任何命令行指令,千万不要放过它的help信息 scons 使用--buildlib=xxx轻松生存库文件,库名称为libxxx.a 4 更多分享 架构师李肯
一个专注于嵌入式iot领域的架构师。有着近10年的嵌入式一线开发经验,深耕iot领域多年,熟知iot领域的业务发展,深度掌握iot领域的相关技术栈,包括但不限于主流rtos内核的实现及其移植、硬件驱动移植开发、网络通讯协议开发、编译构建原理及其实现、底层汇编及编译原理、编译优化及代码重构、主流iot云平台的对接、嵌入式iot系统的架构设计等等。拥有多项iot领域的发明专利,热衷于技术分享,有多年撰写技术博客的经验积累,连续多月获得rt-thread官方技术社区原创技术博文优秀奖,荣获csdn博客专家、csdn物联网领域优质创作者、2021年度csdn&rt-thread技术社区之星、rt-thread官方嵌入式开源社区认证专家、rt-thread 2021年度论坛之星top4、华为云云享专家(嵌入式物联网架构设计师)等荣誉。坚信【知识改变命运,技术改变世界】!
欢迎关注我的github仓库01workstation,日常分享一些开发笔记和项目实战,欢迎指正问题。
同时也非常欢迎关注我的专栏:有问题的话,可以跟我讨论,知无不答,谢谢大家。
科技部部长王志刚:中国已进入人工智能发展的第一方阵
一款250 GB的970EVO Plus来看看它表现如何
中信联研制《数字化转型 参考架构》等标准
中国移动1000亿投资为5G生态建设重大举措
自然形态的LED吊灯Bertjan Pot
【RT-Thread学习笔记】使用scons命令生成静态库
多只二极管取样式电流指示灯
深入分析OPPO RX17 Pro智能手机中的索尼(Sony)IMX316和VCSEL
关于智能教育的相关解读和分析
Atmel携手Celeno开发Wi-Fi Direct遥控技术
编辑视点:Intel与NVIDIA的“核”战争
IDS与防火墙对比
关于征集新材料产业智库专家的通知
常用跨端技术性能问题如何优化解决
申万:卧龙电气价格下降导致蓄电池销售低于预期
倍捷连接器升级线上支付系统,增加线下增值组装产品线
小米6确定发布会时间:4月19日北工大体育馆见!
技术为艺术而生|中国会展xR联盟与中国会展人首次直播活动完美收官,推进xR与会展的深度融合!
鼠标滚轮不灵处理技巧
波分复用系统(WDM),波分复用系统(WDM)结构原理和分类