你好!欢迎来到深圳市品慧电子有限公司!
语言
当前位置:首页 >> 技术中心 >> 传感技术 >> 【RT-Thread学习笔记】使用scons命令生成静态库

【RT-Thread学习笔记】使用scons命令生成静态库


1 问题来源

本问题来源于RT-Thread技术论坛的一个常见问题,当时我回答了这个问题,很荣幸拿了一个最佳答案,为了能够再次消化并进行知识点沉淀,我把这个问题再次抛到这里。 原问题,请戳这里:scons 命令buildlib使用方法

2 实践分析

2.1 不懂就要问

既然不知道怎么用scons,那么我们先看到它的帮助信息,以下命令在scons的主目录执行,即可以找到Sconscript的目录下执行:

  1. rt-thread/bsp/qemu-vexpress-a9$ scons -h
  2. scons: Reading SConscript files ...
  3. drivers/SConscript
  4. applications/SConscript
  5. [, , ]
  6. scons: done reading SConscript files.
  7. usage: scons [OPTION] [TARGET] ...
  8. SCons Options:
  9. -b, -d, -e, -m, -S, -t, -w, --environment-overrides, --no-keep-going,
  10. --no-print-directory, --print-directory, --stop, --touch
  11. Ignored for compatibility.
  12. -c, --clean, --remove Remove specified targets and dependencies.
  13. -C DIR, --directory=DIR Change to DIR before doing anything.
  14. --cache-debug=FILE Print CacheDir debug info to FILE.
  15. --cache-disable, --no-cache
  16. Do not retrieve built targets from CacheDir.
  17. --cache-force, --cache-populate
  18. Copy already-built targets into the CacheDir.
  19. --cache-readonly Do not update CacheDir with built targets.
  20. --cache-show Print build actions for files from CacheDir.
  21. --config=MODE Controls Configure subsystem: auto, force,
  22. cache.
  23. -D Search up directory tree for SConstruct,
  24. build all Default() targets.
  25. --debug=TYPE Print various types of debugging information:
  26. count, duplicate, explain, findlibs, includes,
  27. memoizer, memory, objects, pdb, prepare,
  28. presub, stacktrace, time, action-timestamps.
  29. --diskcheck=TYPE Enable specific on-disk checks.
  30. --duplicate=DUPLICATE Set the preferred duplication methods. Must be
  31. one of hard-soft-copy, soft-hard-copy,
  32. hard-copy, soft-copy, copy
  33. --enable-virtualenv Import certain virtualenv variables to SCons
  34. -f FILE, --file=FILE, --makefile=FILE, --sconstruct=FILE
  35. Read FILE as the top-level SConstruct file.
  36. -h, --help Print defined help message, or this one.
  37. -H, --help-options Print this message and exit.
  38. -i, --ignore-errors Ignore errors from build actions.
  39. -I DIR, --include-dir=DIR Search DIR for imported Python modules.
  40. --ignore-virtualenv Do not import virtualenv variables to SCons
  41. --implicit-cache Cache implicit dependencies
  42. --implicit-deps-changed Ignore cached implicit dependencies.
  43. --implicit-deps-unchanged Ignore changes in implicit dependencies.
  44. --interact, --interactive Run in interactive mode.
  45. -j N, --jobs=N Allow N jobs at once.
  46. -k, --keep-going Keep going when a target can't be made.
  47. --max-drift=N Set maximum system clock drift to N seconds.
  48. --md5-chunksize=N Set chunk-size for MD5 signature computation to
  49. N kilobytes.
  50. -n, --no-exec, --just-print, --dry-run, --recon
  51. Don't build; just print commands.
  52. --no-site-dir Don't search or use the usual site_scons dir.
  53. --profile=FILE Profile SCons and put results in FILE.
  54. -q, --question Don't build; exit status says if up to date.
  55. -Q Suppress "Reading/Building" progress messages.
  56. --random Build dependencies in random order.
  57. -s, --silent, --quiet Don't print commands.
  58. --site-dir=DIR Use DIR instead of the usual site_scons dir.
  59. --stack-size=N Set the stack size of the threads used to run
  60. jobs to N kilobytes.
  61. --taskmastertrace=FILE Trace Node evaluation to FILE.
  62. --tree=OPTIONS Print a dependency tree in various formats: all,
  63. derived, prune, status, linedraw.
  64. -u, --up, --search-up Search up directory tree for SConstruct,
  65. build targets at or below current directory.
  66. -U Search up directory tree for SConstruct,
  67. build Default() targets from local SConscript.
  68. -v, --version Print the SCons version number and exit.
  69. --warn=WARNING-SPEC, --warning=WARNING-SPEC
  70. Enable or disable warnings.
  71. -Y REPOSITORY, --repository=REPOSITORY, --srcdir=REPOSITORY
  72. Search REPOSITORY for source and target files.
  73. Local Options:
  74. --dist make distribution
  75. --dist-strip make distribution and strip useless files
  76. --dist-ide make distribution for RT-Thread Studio IDE
  77. --project-path=PROJECT-PATH
  78. set dist-ide project output path
  79. --project-name=PROJECT-NAME
  80. set project name
  81. --reset-project-config reset the project configurations to default
  82. --cscope Build Cscope cross reference database. Requires
  83. cscope installed.
  84. --clang-analyzer Perform static analyze with Clang-analyzer.
  85. Requires Clang installed. It is recommended to
  86. use with scan-build like this: `scan-build
  87. scons --clang-analyzer` If things goes well,
  88. scan-build will instruct you to invoke
  89. scan-view.
  90. --buildlib=BUILDLIB building library of a component
  91. --cleanlib clean up the library by --buildlib
  92. --target=TARGET set target project: mdk/mdk4/mdk5/iar/vs/vsc/ua/
  93. cdk/ses/makefile/eclipse/codelite/cmake
  94. --stackanalysis thread stack static analysis
  95. --genconfig Generate .config from rtconfig.h
  96. --useconfig=USECONFIG make rtconfig.h from config file.
  97. --verbose print verbose information during build
  98. --menuconfig make menuconfig for RT-Thread BSP
  99. --pyconfig Python GUI menuconfig for RT-Thread BSP
  100. --pyconfig-silent Don`t show pyconfig window

精准匹配下:

  1. rt-thread/bsp/qemu-vexpress-a9$ scons -h | grep buildlib
  2. --buildlib=BUILDLIB building library of a component
  3. --cleanlib clean up the library by --buildlib

2.2 实践出整理

从上面的帮助信息,我们已经找到关键信息了,我们来实践下:

  1. rt-thread/bsp/qemu-vexpress-a9$ scons --buildlib=BUILDLIB
  2. scons: Reading SConscript files ...
  3. b''
  4. drivers/SConscript
  5. applications/SConscript
  6. [, , ]
  7. scons: done reading SConscript files.
  8. scons: Building targets ...
  9. scons: building associated VariantDir targets: build
  10. scons: `.' is up to date.
  11. 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字;发表评论请自觉遵守互联网相关政策法规。

深圳市品慧电子有限公司