1 問(wèn)題來(lái)源
本問(wèn)題來(lái)源于RT-Thread的技術(shù)論壇的一個(gè)常見(jiàn)問(wèn)題,當(dāng)時(shí)我回答了這個(gè)問(wèn)題,很榮幸拿了一個(gè)最佳答案,為了能夠再次消化并進(jìn)行知識(shí)點(diǎn)沉淀,我把這個(gè)問(wèn)題再次拋到這里。 原問(wèn)題,請(qǐng)戳這里:scons 命令buildlib使用方法
2 實(shí)踐分析
2.1 不懂就要問(wèn)
既然不知道怎么用scons,那么我們先看到它的幫助信息,以下命令在scons的主目錄執(zhí)行,即可以找到Sconscript的目錄下執(zhí)行:
-
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
精準(zhǔn)匹配下:
-
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 實(shí)踐出整理
從上面的幫助信息,我們已經(jīng)找到關(guān)鍵信息了,我們來(lái)實(shí)踐下:
-
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.
發(fā)現(xiàn)并沒(méi)有生成,仔細(xì)一看,這個(gè)buildlib=
后面跟的名稱不是亂填的,是需要填寫(xiě)你當(dāng)前目錄下,已經(jīng)使用scons語(yǔ)法配置好的組件,這個(gè)東西在scons里面是叫Group。 通俗來(lái)說(shuō),就是使用buildlib
,一個(gè)Gourp就可以生成一個(gè)庫(kù)。 我們?cè)賮?lái)實(shí)踐下,以bsp/qemu-vexpress-a9的Application
這個(gè)Group為例,在其applications目錄有定義Sconsript:
那么就可以輸入scons--buildlib=Applications
就可以將Applications那個(gè)group定義的C文件編譯打包成一個(gè)靜態(tài)庫(kù),輸出也是位于bsp的目錄中。
3 經(jīng)驗(yàn)總結(jié)
- 任何命令行指令,千萬(wàn)不要放過(guò)它的help信息
-
scons 使用
--buildlib=xxx
輕松生存庫(kù)文件,庫(kù)名稱為libxxx.a
4 更多分享
架構(gòu)師李肯
一個(gè)專注于嵌入式IoT領(lǐng)域的架構(gòu)師。有著近10年的嵌入式一線開(kāi)發(fā)經(jīng)驗(yàn),深耕IoT領(lǐng)域多年,熟知IoT領(lǐng)域的業(yè)務(wù)發(fā)展,深度掌握IoT領(lǐng)域的相關(guān)技術(shù)棧,包括但不限于主流RTOS內(nèi)核的實(shí)現(xiàn)及其移植、硬件驅(qū)動(dòng)移植開(kāi)發(fā)、網(wǎng)絡(luò)通訊協(xié)議開(kāi)發(fā)、編譯構(gòu)建原理及其實(shí)現(xiàn)、底層匯編及編譯原理、編譯優(yōu)化及代碼重構(gòu)、主流IoT云平臺(tái)的對(duì)接、嵌入式IoT系統(tǒng)的架構(gòu)設(shè)計(jì)等等。擁有多項(xiàng)IoT領(lǐng)域的發(fā)明專利,熱衷于技術(shù)分享,有多年撰寫(xiě)技術(shù)博客的經(jīng)驗(yàn)積累,連續(xù)多月獲得RT-Thread官方技術(shù)社區(qū)原創(chuàng)技術(shù)博文優(yōu)秀獎(jiǎng),榮獲CSDN博客專家、CSDN物聯(lián)網(wǎng)領(lǐng)域優(yōu)質(zhì)創(chuàng)作者、2021年度CSDN&RT-Thread技術(shù)社區(qū)之星、RT-Thread官方嵌入式開(kāi)源社區(qū)認(rèn)證專家、RT-Thread 2021年度論壇之星TOP4、華為云云享專家(嵌入式物聯(lián)網(wǎng)架構(gòu)設(shè)計(jì)師)等榮譽(yù)。堅(jiān)信【知識(shí)改變命運(yùn),技術(shù)改變世界】!
歡迎關(guān)注我的github倉(cāng)庫(kù)01workstation,日常分享一些開(kāi)發(fā)筆記和項(xiàng)目實(shí)戰(zhàn),歡迎指正問(wèn)題。
同時(shí)也非常歡迎關(guān)注我的專欄:有問(wèn)題的話,可以跟我討論,知無(wú)不答,謝謝大家。
-
靜態(tài)庫(kù)
+關(guān)注
關(guān)注
0文章
21瀏覽量
7439 -
RT-Thread
+關(guān)注
關(guān)注
31文章
1289瀏覽量
40135 -
scons
+關(guān)注
關(guān)注
0文章
1瀏覽量
955
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
評(píng)論