您好,登录后才能下订单哦!
密码登录
登录注册
点击 登录注册 即表示同意《亿速云用户服务条款》
# 基于MIPS芯片的OpenWRT平台如何交叉编译htop
## 前言
在嵌入式Linux系统中,资源监控工具对于系统维护和性能调优至关重要。htop作为top的增强版,提供了更直观的进程监控体验。本文将详细介绍如何在OpenWRT平台上为MIPS架构交叉编译htop工具。
---
## 一、环境准备
### 1.1 硬件要求
- 支持MIPS架构的路由器/开发板
- 主机系统:推荐x86_64架构的Linux系统(Ubuntu/Debian等)
### 1.2 软件依赖
```bash
sudo apt update
sudo apt install -y build-essential git subversion libncurses5-dev gawk \
zlib1g-dev unzip python3 wget cmake
根据目标设备芯片型号下载对应SDK(以MT7621为例):
wget https://downloads.openwrt.org/releases/21.02.1/targets/ramips/mt7621/openwrt-sdk-21.02.1-ramips-mt7621_gcc-8.4.0_musl.Linux-x86_64.tar.xz
tar -xvf openwrt-sdk-*.tar.xz
cd openwrt-sdk-*
export STAGING_DIR=$(pwd)/staging_dir
export PATH=$PATH:$(pwd)/staging_dir/toolchain-mipsel_24kc_gcc-8.4.0_musl/bin
mipsel-openwrt-linux-gcc -v
应输出类似信息:
gcc version 8.4.0 (OpenWrt GCC 8.4.0 r16325-88151b8303)
git clone https://github.com/htop-dev/htop.git
cd htop
./autogen.sh
./configure \
--host=mipsel-openwrt-linux \
--prefix=/usr \
--disable-unicode \
--enable-static \
CFLAGS="-I$STAGING_DIR/target-mipsel_24kc_musl/usr/include" \
LDFLAGS="-L$STAGING_DIR/target-mipsel_24kc_musl/usr/lib"
关键参数说明:
- --host
:指定目标平台
- --disable-unicode
:禁用Unicode支持(减小体积)
- CFLAGS/LDFLAGS
:指定头文件和库路径
cp -r $STAGING_DIR/target-mipsel_24kc_musl/usr/include/ncurses* ./ncurses/
# 在OpenWRT SDK中编译libnl
make package/libnl/compile V=s
export PKG_CONFIG_PATH=$STAGING_DIR/target-mipsel_24kc_musl/usr/lib/pkgconfig
make -j$(nproc)
file htop
应显示:
htop: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1...
mipsel-openwrt-linux-strip htop
scp htop root@192.168.1.1:/usr/bin/
在设备终端执行:
htop -v
正常应输出版本信息:
htop 3.2.1 - (C) 2004-2022 Hisham Muhammad
解决方案:
# 在设备上安装依赖
opkg update
opkg install libncurses
修改TERM环境变量:
export TERM=linux
修改configure参数:
LDFLAGS="-static -L$STAGING_DIR/..."
include $(TOPDIR)/rules.mk
PKG_NAME:=htop
PKG_VERSION:=3.2.1
PKG_RELEASE:=1
include $(INCLUDE_DIR)/package.mk
define Package/htop
SECTION:=utils
CATEGORY:=Utilities
TITLE:=Interactive process viewer
DEPENDS:=+libncurses
endef
define Package/htop/install
$(INSTALL_DIR) $(1)/usr/bin
$(INSTALL_BIN) $(PKG_BUILD_DIR)/htop $(1)/usr/bin/
endef
$(eval $(call BuildPackage,htop))
通过本文的步骤,我们成功在OpenWRT平台上为MIPS架构交叉编译了htop工具。该过程涉及工具链配置、依赖管理和交叉编译技巧,这些方法同样适用于其他软件的交叉编译场景。建议在实际操作时根据具体芯片型号调整环境参数。
注意:不同OpenWRT版本可能需要调整SDK路径和库版本,建议参考官方文档进行适配。 “`
(全文约1450字,实际字数可能因代码块格式略有差异)
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。