Search code examples
githubrustgithub-actionslinker-errorslibpcap

How to fix "cannot find -lpcap" error when building Rust in Github actions?


I have a small Rust project on Github and I added a rust.yml file for the actions to build the project and run the tests automatically.

The build crashes while compiling libc v0.2.153 with the following:

note: /usr/bin/ld: cannot find -lpcap: No such file or directory

The YAML file I'm using for the actions is the basic Rust one that Github provides:

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: Build
      run: cargo build --verbose
    - name: Run tests
      run: cargo test --verbose

Do I need to add some libraries or paths to the file?


Solution

  • I needed to install libpcap-dev.

    Just added this to the jobs build section of the YAML file before the build step:

        - name: Install libpcap
          run: sudo apt-get update && sudo apt-get install -y libpcap-dev