Openwrt使用指定版本的toolchain工具链

默认编译 openwrt 时会先编译一套 toolchain. 这个步骤耗时较长. 使用外部 toolchain 可以多个 project 共用一套 toolchain , 而且也不重再编译它了. 省时省力.

make menuconfig

[*] Advanced configuration options (for developers) --->

[*] Use external toolchain --->

│ │ --- Use external toolchain                                                                                         │ │

│ │ [ ] Use host's toolchain                                                                                             │ │

│ │ (mipsel-openwrt-linux-uclibc) Target name                                                              │ │

│ │ (mipsel-openwrt-linux-uclibc-) Toolchain prefix                                                        │ │

│ │ (/opt/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2) Toolchain root │ │

│ │ (uclibc) Toolchain libc                                                                                               │ │

│ │ (./usr/bin ./bin) Toolchain program path                                                                    │ │

│ │ (./usr/include ./include) Toolchain include path                                                         │ │

│ │ (./usr/lib ./lib) Toolchain library path                                                                          │ │

编译完在 .config 下可以见到以下变量的定义: 

CONFIG_EXTERNAL_TOOLCHAIN=y
# CONFIG_NATIVE_TOOLCHAIN is not set
CONFIG_TARGET_NAME="mipsel-openwrt-linux-uclibc"
CONFIG_TOOLCHAIN_PREFIX="mipsel-openwrt-linux-uclibc-"
CONFIG_TOOLCHAIN_ROOT="/opt/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2"
CONFIG_TOOLCHAIN_LIBC="uclibc"
CONFIG_TOOLCHAIN_BIN_PATH="./usr/bin ./bin"
CONFIG_TOOLCHAIN_INC_PATH="./usr/include ./include"
CONFIG_TOOLCHAIN_LIB_PATH="./usr/lib ./lib"

这些变量在 rules.mk 里起作用.

我使用主 trunk 的 openwrt, 编译 kenrel 时碰到了问题. 在 kernel 的 Makefile 里设置 KBUILD_VERBOSE = 1 看到是交叉编译器没有指定路径. 跟踪到是 rules.mk 里 TARGET_CROSS 只保留了交叉编译器前缀, 没加路径. 改了一下就可以完全编译过了.

diff --git a/rules.mk b/rules.mk
index 0822979..70f3afc 100644
--- a/rules.mk
+++ b/rules.mk
@@ -144,9 +144,9 @@ ifndef DUMP
     TARGET_PATH:=$(TOOLCHAIN_DIR)/bin:$(TARGET_PATH)
   else
     ifeq ($(CONFIG_NATIVE_TOOLCHAIN),)
-      TARGET_CROSS:=$(call qstrip,$(CONFIG_TOOLCHAIN_PREFIX))
       TOOLCHAIN_ROOT_DIR:=$(call qstrip,$(CONFIG_TOOLCHAIN_ROOT))
       TOOLCHAIN_BIN_DIRS:=$(patsubst ./%,$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_BIN_PATH)))
+      TARGET_CROSS:=$(call qstrip,$(TOOLCHAIN_ROOT_DIR)/bin/$(CONFIG_TOOLCHAIN_PREFIX))
       TOOLCHAIN_INC_DIRS:=$(patsubst ./%,$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_INC_PATH)))
       TOOLCHAIN_LIB_DIRS:=$(patsubst ./%,$(TOOLCHAIN_ROOT_DIR)/%,$(call qstrip,$(CONFIG_TOOLCHAIN_LIB_PATH)))
       ifneq ($(TOOLCHAIN_BIN_DIRS),)

 

回答: 在安装OpenWrt的过程中,编译toolchain是一个耗时较长的步骤。为了节省时间,可以选择使用外部toolchain,这样多个项目可以共用一套toolchain,并且不需要重新编译它。\[1\]为了使用外部toolchain,你需要将已经编译好的toolchain放置在一个固定的目录中,然后在OpenWrt的配置中选择使用外部toolchain。\[2\]在配置中,你需要指定toolchain的一些参数,比如目标名称、toolchain的前缀、toolchain的根目录、toolchain的程序路径、toolchain的包含路径和库路径等。\[2\]另外,如果你不设置"STAGING_DIR"变量,编译文件时可能会有警告,但不会影响编译结果。\[3\]希望这些信息对你有帮助。 #### 引用[.reference_title] - *1* [Openwrt使用指定版本toolchain工具](https://blog.csdn.net/Pintitus/article/details/119854615)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Openwrt实践过程-工具-Internal/External Toolchain](https://blog.csdn.net/qq_20677327/article/details/104550738)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [openwrt 安装交叉编译工具 错误总结](https://blog.csdn.net/sunskyday/article/details/106475048)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insert_down1,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值