移植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:其他的坑暂时没有遇到,欢迎评论补充

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值