Rohan Aluguri
Rohan Aluguri

Reputation: 53

asm/types.h Error during compilation of ebpf code

Here i am trying to compile a eBPF code. and used the following command for compilation. command: clang -O2 -target bpf -c your_ebpf_program.c -o your_ebpf_program.o

error: In file included from my_program.c:2:/usr/include/linux/bpf.h:11:10: fatal error: 'asm/types.h' file not found#include <asm/types.h> ^~~~~~~~~~~~~1 error generated.

I used clang as a compiler for compilation. All the required libraries are downloaded and yet got an error stating asm/types.h is not found. All the linux header files are updated.

Upvotes: 3

Views: 7000

Answers (4)

Vibhor Phalke
Vibhor Phalke

Reputation: 1

I encountered this error while running go generate that looked like this:

fatal error: 'asm/types.h' file not found
    5 | #include <asm/types.h>
      |          ^~~~~~~~~~~~~
1 error generated.
Error: compile: exit status 1
exit status 1
gen.go:3: running "go": exit status 1

It turns out the issue was caused by a bad symbolic link for /usr/include/asm.But you may not have any symbolic link , but this solution will work for you just skip first step. Here's how I fixed it:

  1. Check the current link I ran:

    ls -l /usr/include/asm
    

    This showed that the link was pointing to aarch64-linux-gnu/asm, which is for ARM architectures. My system is x86_64, so this was wrong.

  2. Find the correct asm/types.h I searched for types.h files in the asm directories:

    find /usr/include -name "types.h" | grep asm
    

    This pointed me to /usr/include/x86_64-linux-gnu/asm/types.h.

  3. Fix the symbolic link I removed the incorrect link and created a new one pointing to the correct directory:

    sudo rm /usr/include/asm
    sudo ln -s /usr/include/x86_64-linux-gnu/asm /usr/include/asm
    
  4. Verify the fix I ran:

    ls -l /usr/include/asm
    

    Now the link points to /usr/include/x86_64-linux-gnu/asm.

  5. Retry the command After this, running go generate worked perfectly without any errors.

Upvotes: 0

doniacld
doniacld

Reputation: 1

I am using Lima with the following architecture:

images:
  - location: 'https://cloud-images.ubuntu.com/releases/24.04/release-20240423/ubuntu-24.04-server-cloudimg-arm64.img'
    arch: aarch64

and I had to add the symlink and change the path to the architecture:

sudo ln -s /usr/include/aarch64-linux-gnu/asm /usr/include/asm

Upvotes: 0

Alex0x090
Alex0x090

Reputation: 1

Try to install Libbpf:

sudo apt update -y
sudo apt-get -y install libbpf-dev

Upvotes: -1

Dylan Reimerink
Dylan Reimerink

Reputation: 7968

You might need to install additional kernel headers. On Ubuntu for example you can do so by executing

apt install linux-headers-`uname -r`

Apparently on some platforms you might need to symlink a directory as well. But I am not sure that is always required. Source 1 Source 2

sudo ln -s /usr/include/x86_64-linux-gnu/asm /usr/include/asm

Upvotes: 10

Related Questions