You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决GitHub Actions中构建Rust项目时的‘cannot find -lpcap’错误?

解决方案

报错 /usr/bin/ld: cannot find -lpcap: No such file or directory 是因为GitHub Actions使用的Ubuntu-latest运行环境默认未安装libpcap开发库,链接器找不到对应的库文件导致的。

你需要在GitHub Actions工作流中添加安装系统依赖的步骤,修改后的完整YAML配置如下:

name: Rust

on:
  push:
    branches: [ "master" ]
  pull_request:
    branches: [ "master" ]

env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3
    - name: Install system dependencies
      run: sudo apt-get update && sudo apt-get install -y libpcap-dev
    - name: Build
      run: cargo build --verbose
    - name: Run tests
      run: cargo test --verbose

说明

新增的Install system dependencies步骤会先更新Ubuntu的软件包索引,再安装libpcap-dev包——这个包包含了链接器所需的libpcap库文件和头文件,安装后即可解决链接失败的问题。

内容的提问来源于stack exchange,提问作者Sergio García

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 20:14:50