Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

627
Views
Can't compile sample bpf program, bpf/bpf.h is missing

I'm trying to compile the sample bpf program in Linux source code. So I downloaded the current kernel source code and entered samples/bpf folder

apt source linux
cd linux-*/samples/bpf

Then I tried to compile a sample program with gcc:

# gcc sock_example.c
sock_example.c:29:10: fatal error: bpf/bpf.h: No such file or directory
   29 | #include <bpf/bpf.h>
      |          ^~~~~~~~~~~
compilation terminated.

And I'm unable to find bpf/bpf.h with apt-file

# apt-file find bpf/bpf.h
(no output)

What was wrong?

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You need to install libbpf:

git clone --depth 1 https://github.com/libbpf/libbpf
cd src
sudo make install
over 4 years ago · Santiago Trujillo Report

0

The Linux eBPF samples come with a rather long Makefile. It handles a lot of cases and integrates well with the kernel building workflow, but makes it more complicated to build the samples outside of the kernel tree.

For example, this Makefile adds a number of includes directories, such as TPROGS_CFLAGS += -I$(srctree)/tools/lib/, meaning that bpf/bpf.h will not be fetched from your OS' libraries but from tools/lib/ under your kernel repository.

Here are a few options that you can consider to compile your program:

  • Adjust the existing Makefile to use it to build your own programs, for example by adding your kernel code to the tprogs-y target.
  • Install libbpf from the kernel repo (sudo make -C tools/lib/bpf install) or from its GitHub mirror. This should install the headers, and gcc should then be able to find them.
  • Adjust your compile option to tell gcc where to look for the header (gcc -I <path/to/linux>/tools/lib).
  • (Adjust the include path in #include <bpf/bpf.h> to make it point to your library.)
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!