这里以mipsbe架构为例,编译tcpdump-4.8.1以及依赖库libpcap-1.8.1(自行搜索官方源码下载哦)
编译环境的ubuntu(windows10 WSL)
这里的编译工具是从openwrt下载的:openwrt-toolchain-22.03.5-malta-be_gcc-11.2.0_musl.Linux-x86_64.tar,假设解压后放在路径~/toolchain/mipsbe_24kc-owrt–musl–gcc-11.2.0
libpcap和tcpdump放同一级目录
编译libpcap
sudo apt install flex bison
./configure CC=~/toolchain/mipsbe_24kc-owrt--musl--gcc-11.2.0/bin/mips-openwrt-linux-gcc --host=mips-openwrt-linux --with-pcap=linux
make
静态编译tcpdump,会自动连接同一级目录的libpcap目录里编译好的库文件
./configure CC=~/toolchain/mipsbe_24kc-owrt--musl--gcc-11.2.0/bin/mips-openwrt-linux-gcc --host=mips-openwrt-linux CFLAGS=-static
make
#瘦身
~/toolchain/mipsbe_24kc-owrt–musl–gcc-11.2.0/bin/mips-openwrt-linux-strip -s tcpdump
#检测是否完全静态编译的,没有依赖库
readelf -a tcpdump|grep NEED