ARM32静态交叉编译并使用pidstat教程

一、前提准备

  1. 主机环境

    • 操作系统:Ubuntu/Debian 系统
    • 本教程以 sysstat-12.7.7 为例,可按需替换版本号。
  2. 交叉编译工具链

    bash 复制代码
    sudo apt-get update
    sudo apt-get install \
      gcc-arm-linux-gnueabihf \
      g++-arm-linux-gnueabihf \
      binutils-arm-linux-gnueabihf \
      libc6-dev-armhf-cross
  3. (可选)目标根文件系统 Sysroot

    如果有目标板的根文件系统,解压或挂载到 /opt/arm-sysroot,以便正确找到头文件和库。


二、下载源码

  1. 克隆官方仓库并切换到指定版本:

    bash 复制代码
    git clone https://github.com/sysstat/sysstat.git
    cd sysstat
    git checkout 12.7.7
  2. 若仓库中没有 configure 脚本,可先运行:

    bash 复制代码
    ./autogen.sh

三、配置交叉编译环境

在源码根目录下,导出交叉链工具和静态链接标志:

bash 复制代码
# 1. 指定交叉编译工具
export CC=arm-linux-gnueabihf-gcc
export CXX=arm-linux-gnueabihf-g++
export AR=arm-linux-gnueabihf-ar
export AS=arm-linux-gnueabihf-as
export LD=arm-linux-gnueabihf-ld
export RANLIB=arm-linux-gnueabihf-ranlib
export STRIP=arm-linux-gnueabihf-strip

# 2. 指定 sysroot、优化与静态链接
export SYSROOT=/opt/arm-sysroot
export CFLAGS="--sysroot=$SYSROOT -O2 -static"
export LDFLAGS="--sysroot=$SYSROOT -static"

# 3. 运行 configure(prefix 可自定义)
./configure \
  --host=arm-linux-gnueabihf \
  --prefix=/opt/sysstat-arm32

说明

  • --host 指定目标架构,不能用 --enable-static,静态链接由 -static 控制。
  • 若无 sysroot,可去掉相关 --sysroot 参数,但需保证交叉链能找到库和头文件。

四、编译并打包

  1. 编译

    bash 复制代码
    make -j$(nproc)
  2. 安装到本地临时根目录

    bash 复制代码
    make DESTDIR=$HOME/sysstat-arm32-root install
  3. 打包

    bash 复制代码
    cd $HOME/sysstat-arm32-root/opt/sysstat-arm32
    tar czvf ~/pidstat-arm32-static.tar.gz bin/pidstat lib/ share/

五、部署到 ARM32 设备

  1. 拷贝文件

    bash 复制代码
    scp ~/pidstat-arm32-static.tar.gz user@arm-device:/tmp
    ssh user@arm-device
    cd /usr/local
    sudo tar xzvf /tmp/pidstat-arm32-static.tar.gz
    sudo ln -s /usr/local/bin/pidstat /usr/bin/pidstat
  2. 检查依赖

    bash 复制代码
    file /usr/local/bin/pidstat
    # 应显示 "statically linked"

六、使用示例

登录到 ARM32 设备后,运行:

bash 复制代码
# 每秒报告一次进程级 I/O 使用,连续 5 次
pidstat -d 1 5

# 查看内存与 CPU 使用
pidstat -r -u 2 3

若一切正常,即说明你已成功编译、部署并运行静态链接的 ARM32 版 pidstat

如有其它 sysstat 工具需求(如 iostatmpstat),同样放在 bin/ 目录下,可一并使用。祝编译顺利!

相关推荐
青草地溪水旁3 小时前
socketpair深度解析:Linux中的“对讲机“创建器
linux·服务器·socket编程
想唱rap4 小时前
Linux指令(1)
linux·运维·服务器·笔记·新浪微博
woshihonghonga4 小时前
Ubuntu20.04下的Pytorch2.7.1安装
linux·人工智能·ubuntu
字节高级特工4 小时前
网络协议分层与Socket编程详解
linux·服务器·开发语言·网络·c++·人工智能·php
minji...5 小时前
Linux 权限的概念及shell命令运行原理
linux·运维·服务器
欢鸽儿6 小时前
理解Vivado的IP综合策略:“Out-of-Context Module Runs
linux·ubuntu·fpga
HappyGame026 小时前
Linux多线程编程
linux
躺着数星星6 小时前
Linux中安装es
linux·elasticsearch·jenkins
带土16 小时前
32位ubuntu14.0.4安装chrome
linux·chrome
欢鸽儿6 小时前
Vivado综合通关指南:从IP打包失败到工具崩溃的四重考验
linux·ubuntu·fpga