移植iftop到mips平台

概述

  • 由于边缘计算平台选用了mips架构的cpu,需要测试一下网络使用情况,但是没有iftop工具,自己动手编译一个

  • 平台,主机是基于intel的linux系统,有现成的mipsel交叉编译器

步骤

1、下载iftop的源码: https://pdw.ex-parrot.com/iftop/

ps:官网提示,需要依赖的库

Requirements
	libpcap
	libcurses

2、我是放到docker进行编译的,当然主机也可以

3、启动容器,将iftop源码和交叉编译器挂载到容器,使用主机编译请跳转到4

docker run -it --name iftop -v /xxx/iftop-0.17:/root -v \
	/xxx/x2000/ingenic:/root/ingenic d17f872f4f6a /bin/bash

4、设置环境变量

export PATH=$PATH:/root/ingenic/tools/toolchains/mips-gcc720-glibc229/bin/

root@044b362f841f:~/iftop-0.17# mips-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=mips-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/root/ingenic/tools/toolchains/mips-gcc720-glibc229/bin/../libexec/gcc/mips-linux-gnu/7.2.0/lto-wrapper
Target: mips-linux-gnu

5、进入iftop源码目录,执行configure,

mkdir -p /usr/data/projects/iftop

./configure --prefix=/usr/data/projects/iftop \
--host=mips-linux-gnu \
CPPFLAGS="-I/root/ingenic/buildroot/buildroot/output/host/mipsel-buildroot-linux-gnu/sysroot/usr/include" \
LDFLAGS="-L/root/ingenic/buildroot/buildroot/output/target/usr/lib -lpcap -lnl-genl-3 -lnl-3 -lc" 

make && make install

ps1:iftop需要依赖pcap,我这个交叉编译工具里面包含了pcap的库,如果没有需要下载pcap源码进行编译

ps2:神奇啊,我没有指定libcurses也可以编译过,哈哈,没时间详细研究了

ps3:如果中间提示缺少库,可以通过mipsel的ldd工具查看libpcap.so以来的库,手动添加一下

root@044b362f841f:~/iftop-0.17# mips-linux-gnu-ldd /root/ingenic/buildroot/buildroot/output/target/usr/lib/libpcap.so
ldd: cache '/etc/ld.so.cache' is corrupt
checking sub-depends for 'not found'
checking sub-depends for 'not found'
checking sub-depends for 'not found'
        libnl-genl-3.so.200 => not found (0x00000000)
        libnl-3.so.200 => not found (0x00000000)
        libc.so.6 => not found (0x00000000)
        not a dynamic executable

6、最后编译完成后,在/usr/data/projects/iftop目录下面会生成iftop可执行文件

root@044b362f841f:~/iftop-0.17# file /usr/data/projects/iftop/sbin/iftop 

/usr/data/projects/iftop/sbin/iftop: ELF 32-bit LSB executable, MIPS, MIPS32 rel2 version 1 (SYSV),
dynamically linked, interpreter /lib/ld-linux-mipsn8.so.1, for GNU/Linux 3.10.14, with debug_info, not stripped

ps:其他的坑暂时没有遇到,欢迎评论补充

相关推荐
Lapsey3 个月前
龙芯杯个人赛记录
mips
shencz20004 个月前
MIPS极简史:风雨40年,两度IPO六次被收购,读后感
龙芯·mips
开着拖拉机回家7 个月前
【Linux】iftop命令详解
linux·服务器·网络流量监控·iftop
爱尚你19931 年前
Linux网络监控工具 - iftop
linux·运维·网络·iftop·nethogs