0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

【RT-Thread學(xué)習(xí)筆記】使用scons命令生成靜態(tài)庫

嵌入式物聯(lián)網(wǎng)開發(fā) ? 來源:嵌入式物聯(lián)網(wǎng)開發(fā) ? 作者:嵌入式物聯(lián)網(wǎng)開發(fā) ? 2022-07-27 09:13 ? 次閱讀

1 問題來源

本問題來源于RT-Thread技術(shù)論壇的一個常見問題,當時我回答了這個問題,很榮幸拿了一個最佳答案,為了能夠再次消化并進行知識點沉淀,我把這個問題再次拋到這里。 原問題,請戳這里:scons 命令buildlib使用方法

在這里插入圖片描述

2 實踐分析

2.1 不懂就要問

既然不知道怎么用scons,那么我們先看到它的幫助信息,以下命令在scons的主目錄執(zhí)行,即可以找到Sconscript的目錄下執(zhí)行:

  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 實踐出整理

從上面的幫助信息,我們已經(jīng)找到關(guān)鍵信息了,我們來實踐下:

  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.

發(fā)現(xiàn)并沒有生成,仔細一看,這個buildlib=后面跟的名稱不是亂填的,是需要填寫你當前目錄下,已經(jīng)使用scons語法配置好的組件,這個東西在scons里面是叫Group。 通俗來說,就是使用buildlib,一個Gourp就可以生成一個庫。 我們再來實踐下,以bsp/qemu-vexpress-a9的Application這個Group為例,在其applications目錄有定義Sconsript:

在這里插入圖片描述

那么就可以輸入scons--buildlib=Applications

在這里插入圖片描述

就可以將Applications那個group定義的C文件編譯打包成一個靜態(tài)庫,輸出也是位于bsp的目錄中。

3 經(jīng)驗總結(jié)

  • 任何命令行指令,千萬不要放過它的help信息
  • scons 使用--buildlib=xxx輕松生存庫文件,庫名稱為libxxx.a

4 更多分享

架構(gòu)師李肯

一個專注于嵌入式IoT領(lǐng)域的架構(gòu)師。有著近10年的嵌入式一線開發(fā)經(jīng)驗,深耕IoT領(lǐng)域多年,熟知IoT領(lǐng)域的業(yè)務(wù)發(fā)展,深度掌握IoT領(lǐng)域的相關(guān)技術(shù)棧,包括但不限于主流RTOS內(nèi)核的實現(xiàn)及其移植、硬件驅(qū)動移植開發(fā)、網(wǎng)絡(luò)通訊協(xié)議開發(fā)、編譯構(gòu)建原理及其實現(xiàn)、底層匯編及編譯原理、編譯優(yōu)化及代碼重構(gòu)、主流IoT云平臺的對接、嵌入式IoT系統(tǒng)的架構(gòu)設(shè)計等等。擁有多項IoT領(lǐng)域的發(fā)明專利,熱衷于技術(shù)分享,有多年撰寫技術(shù)博客的經(jīng)驗積累,連續(xù)多月獲得RT-Thread官方技術(shù)社區(qū)原創(chuàng)技術(shù)博文優(yōu)秀獎,榮獲CSDN博客專家、CSDN物聯(lián)網(wǎng)領(lǐng)域優(yōu)質(zhì)創(chuàng)作者、2021年度CSDN&RT-Thread技術(shù)社區(qū)之星、RT-Thread官方嵌入式開源社區(qū)認證專家、RT-Thread 2021年度論壇之星TOP4、華為云云享專家(嵌入式物聯(lián)網(wǎng)架構(gòu)設(shè)計師)等榮譽。堅信【知識改變命運,技術(shù)改變世界】!

歡迎關(guān)注我的github倉庫01workstation,日常分享一些開發(fā)筆記和項目實戰(zhàn),歡迎指正問題。

同時也非常歡迎關(guān)注我的專欄:有問題的話,可以跟我討論,知無不答,謝謝大家。

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • 靜態(tài)庫
    +關(guān)注

    關(guān)注

    0

    文章

    21

    瀏覽量

    7414
  • RT-Thread
    +關(guān)注

    關(guān)注

    31

    文章

    1249

    瀏覽量

    39727
  • scons
    +關(guān)注

    關(guān)注

    0

    文章

    1

    瀏覽量

    946
收藏 人收藏

    評論

    相關(guān)推薦

    RT-Thread系統(tǒng)中的Scons構(gòu)建工具資料推薦

    文件中可以調(diào)用 Python 標準進行各類復(fù)雜的處理,而不局限于 Makefile 設(shè)定的規(guī)則。2.1 RT-ThreadScons的腳本結(jié)構(gòu)SCons 使用 SConscrip
    發(fā)表于 05-07 15:35

    RT-Thread Nano入門學(xué)習(xí)筆記

    RT-Thread Nano入門學(xué)習(xí)筆記
    發(fā)表于 11-26 12:36 ?20次下載
    <b class='flag-5'>RT-Thread</b> Nano入門<b class='flag-5'>學(xué)習(xí)</b><b class='flag-5'>筆記</b>

    RT-Thread 應(yīng)用筆記 - RTC Alarm 組件的使用

    RT-Thread 應(yīng)用筆記 - 不正確使用LOG也會引發(fā)hard faultRT-Thread 應(yīng)用筆記 - RTC Alarm 組件的使用RT-
    發(fā)表于 01-25 18:18 ?10次下載
    <b class='flag-5'>RT-Thread</b> 應(yīng)用<b class='flag-5'>筆記</b> - RTC Alarm 組件的使用

    RT-Thread 內(nèi)核學(xué)習(xí)筆記 - 理解defunct僵尸線程

    RT-Thread 內(nèi)核學(xué)習(xí)筆記 - 內(nèi)核對象rt_objectRT-Thread 內(nèi)核學(xué)習(xí)筆記
    發(fā)表于 01-25 18:19 ?8次下載
    <b class='flag-5'>RT-Thread</b> 內(nèi)核<b class='flag-5'>學(xué)習(xí)</b><b class='flag-5'>筆記</b> - 理解defunct僵尸線程

    RT-Thread 內(nèi)核學(xué)習(xí)筆記 - 設(shè)備模型rt_device的理解

    RT-Thread 內(nèi)核學(xué)習(xí)筆記 - 內(nèi)核對象rt_objectRT-Thread 內(nèi)核學(xué)習(xí)筆記
    發(fā)表于 01-25 18:19 ?8次下載
    <b class='flag-5'>RT-Thread</b> 內(nèi)核<b class='flag-5'>學(xué)習(xí)</b><b class='flag-5'>筆記</b> - 設(shè)備模型<b class='flag-5'>rt</b>_device的理解

    RT-Thread 內(nèi)核學(xué)習(xí)筆記 - 內(nèi)核對象鏈表結(jié)構(gòu)深入理解

    RT-Thread 內(nèi)核學(xué)習(xí)筆記 - 內(nèi)核對象rt_objectRT-Thread 內(nèi)核學(xué)習(xí)筆記
    發(fā)表于 01-25 18:23 ?6次下載
    <b class='flag-5'>RT-Thread</b> 內(nèi)核<b class='flag-5'>學(xué)習(xí)</b><b class='flag-5'>筆記</b> - 內(nèi)核對象鏈表結(jié)構(gòu)深入理解

    RT-Thread 內(nèi)核學(xué)習(xí)筆記 - 內(nèi)核對象初始化鏈表組織方式

    RT-Thread 內(nèi)核學(xué)習(xí)筆記 - 內(nèi)核對象rt_objectRT-Thread 內(nèi)核學(xué)習(xí)筆記
    發(fā)表于 01-25 18:24 ?3次下載
    <b class='flag-5'>RT-Thread</b> 內(nèi)核<b class='flag-5'>學(xué)習(xí)</b><b class='flag-5'>筆記</b> - 內(nèi)核對象初始化鏈表組織方式

    RT-Thread 內(nèi)核學(xué)習(xí)筆記 - 內(nèi)核對象操作API

    RT-Thread 內(nèi)核學(xué)習(xí)筆記 - 內(nèi)核對象rt_objectRT-Thread 內(nèi)核學(xué)習(xí)筆記
    發(fā)表于 01-25 18:26 ?7次下載
    <b class='flag-5'>RT-Thread</b> 內(nèi)核<b class='flag-5'>學(xué)習(xí)</b><b class='flag-5'>筆記</b> - 內(nèi)核對象操作API

    RT-Thread 4.1.0的CMake構(gòu)建教程

    CMake 支持 在 RT-Thread 4.1.0 正式發(fā)布版中,添加了對 CMake 的支持。開發(fā)者可以使用 SCons 工具來生成 CMakeLists.txt 文件。 為何要支持 CMake
    的頭像 發(fā)表于 05-25 11:06 ?3235次閱讀

    RT-Thread全球技術(shù)大會:關(guān)于SCons構(gòu)建引擎的主要部分介紹

    RT-Thread全球技術(shù)大會:關(guān)于SCons構(gòu)建引擎的主要部分介紹 ? ? ? ? 審核編輯:彭靜 ?
    的頭像 發(fā)表于 05-27 14:55 ?935次閱讀
    <b class='flag-5'>RT-Thread</b>全球技術(shù)大會:關(guān)于<b class='flag-5'>SCons</b>構(gòu)建引擎的主要部分介紹

    RT-Thread學(xué)習(xí)筆記 RT-Thread的架構(gòu)概述

    RT-Thread 簡介 作為一名 RTOS 的初學(xué)者,也許你對 RT-Thread 還比較陌生。然而,隨著你的深入接觸,你會逐漸發(fā)現(xiàn) RT-Thread 的魅力和它相較于其他同類型 RTOS
    的頭像 發(fā)表于 07-09 11:27 ?4388次閱讀
    <b class='flag-5'>RT-Thread</b><b class='flag-5'>學(xué)習(xí)</b><b class='flag-5'>筆記</b> <b class='flag-5'>RT-Thread</b>的架構(gòu)概述

    RT-Thread學(xué)習(xí)筆記】Makefile的FORCE

    RT-Thread學(xué)習(xí)筆記】十分鐘學(xué)會Makefile的FORCE
    的頭像 發(fā)表于 07-30 13:55 ?2342次閱讀
    【<b class='flag-5'>RT-Thread</b><b class='flag-5'>學(xué)習(xí)</b><b class='flag-5'>筆記</b>】Makefile的FORCE

    RT-Thread學(xué)習(xí)筆記】如何抓取終端的網(wǎng)絡(luò)報文

    RT-Thread學(xué)習(xí)筆記】如何抓取終端的網(wǎng)絡(luò)報文?
    的頭像 發(fā)表于 07-30 13:57 ?2658次閱讀
    【<b class='flag-5'>RT-Thread</b><b class='flag-5'>學(xué)習(xí)</b><b class='flag-5'>筆記</b>】如何抓取終端的網(wǎng)絡(luò)報文

    RT-Thread學(xué)習(xí)筆記】用memwatch排除內(nèi)存泄露

    RT-Thread學(xué)習(xí)筆記】使用memwatch排除內(nèi)存泄露
    的頭像 發(fā)表于 07-30 14:01 ?2151次閱讀
    【<b class='flag-5'>RT-Thread</b><b class='flag-5'>學(xué)習(xí)</b><b class='flag-5'>筆記</b>】用memwatch排除內(nèi)存泄露

    基于RT-Thread Studio學(xué)習(xí)

    前期準備:從官網(wǎng)下載 RT-Thread Studio,弄個賬號登陸,開啟rt-thread學(xué)習(xí)之旅。
    的頭像 發(fā)表于 05-15 11:00 ?3658次閱讀
    基于<b class='flag-5'>RT-Thread</b> Studio<b class='flag-5'>學(xué)習(xí)</b>