如何解决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
相关产品推荐
相关产品推荐

