目录 1. 安装编译工具 2. 设置环境变量 3. 编译libpcap 4. 编译TCPDUMP 4.1 克隆仓库与生成构建环境 4.2 静态链接LIBPCAP 4.3 动态链接LIBPCAP 4.4 构建与安装 5. 查看交叉编译结果
1. 安装编译工具
sudo apt-get install -y autoconf automake libtool pkg-config
2. 设置环境变量
export TLCS_ROOT = .. .-x86_64_aarch64-linux-gnu
3. 编译libpcap
3.1 安装依赖
sudo apt-get install -y flex bison
3.2 交叉编译
git clone --recursive -b libpcap-1.9.1 https://github.com/the-tcpdump-group/libpcap.git
cd libpcap
autoreconf -fiv
rm -rf build_aarch64; mkdir build_aarch64 && cd build_aarch64
env -v \
AR = ${TLCS_ROOT} /bin/aarch64-linux-gnu-ar \
CC = ${TLCS_ROOT} /bin/aarch64-linux-gnu-gcc \
RANLIB = ${TLCS_ROOT} /bin/aarch64-linux-gnu-ranlib \
CFLAGS = "-O2" \
.. /configure \
--with-pcap= linux \
--host= aarch64-linux-gnu \
--prefix= ${HOME } /libs/libpcap-1.9.1
make -j16 && make install
4. 编译TCPDUMP
4.1 克隆仓库与生成构建环境
git clone --recursive -b tcpdump-4.9.3 https://github.com/the-tcpdump-group/tcpdump.git
cd tcpdump
autoreconf -fiv
rm -rf build_aarch64; mkdir build_aarch64 && cd build_aarch64
4.2 静态链接LIBPCAP
env -v \
CC = ${TLCS_ROOT} /bin/aarch64-linux-gnu-gcc \
AR = ${TLCS_ROOT} /bin/aarch64-linux-gnu-ar \
RANLIB = ${TLCS_ROOT} /bin/aarch64-linux-gnu-ranlib \
CPPFLAGS = "-I${HOME } /libs/libpcap-1.9.1/include" \
LDFLAGS = "-L${HOME } /libs/libpcap-1.9.1/lib" \
LIBS = "-static -lpcap" \
CFLAGS = "-O2" \
.. /configure \
--host= aarch64-linux-gnu \
--prefix= ${HOME } /libs/libtcpdump-4.9.3
4.3 动态链接LIBPCAP
env -v \
CC = ${TLCS_ROOT} /bin/aarch64-linux-gnu-gcc \
AR = ${TLCS_ROOT} /bin/aarch64-linux-gnu-ar \
RANLIB = ${TLCS_ROOT} /bin/aarch64-linux-gnu-ranlib \
CPPFLAGS = "-I${HOME } /libs/libpcap-1.9.1/include" \
LDFLAGS = "-L${HOME } /libs/libpcap-1.9.1/lib" \
LIBS = "-dynamic -lpcap" \
CFLAGS = "-O2" \
.. /configure \
--host= aarch64-linux-gnu \
--prefix= ${HOME } /libs/libtcpdump-4.9.3
4.4 构建与安装
make -j16 && make install
5. 查看交叉编译结果
5.1 文件布局
cd ${HOME } /libs
tree . -L 3