vmware-archive / p4c-xdp

Backend for the P4 compiler targeting XDP
Apache License 2.0
171 stars 26 forks source link

How to include ebpf_xdp.h #129

Open MarcusWichelmann opened 3 years ago

MarcusWichelmann commented 3 years ago

When compiling a .p4 file as described in the readme, clang cannot find the ebpf_xdp.h header:

/tmp/xdp1.h:6:10: fatal error: 'ebpf_xdp.h' file not found

The header file is included in this repository and says

This file contains all functions and definitions necessary for the xdp target C code to compile. It must be included with any file generated by the p4c-xdp compiler.

But how am I supposed to include it? Of course, I could hack this together somehow, but I'm wondering what is the correct way you intended for this. 😄 Maybe the Readme needs an update?

mihaibudiu commented 3 years ago

The C compiler can be given a -I flag to indicate a path where headers are expected to be found. So probably adding clang -I tests .... would work (assuming you are invoking clang in the root directory of the p4c-xdp project, since the ebpf_xdp.h file is there.) If this works for you we can update the README.

MarcusWichelmann commented 3 years ago

Thank you for your quick response.

Yes, that's what I meant with hack this together. 😄 I managed to build it now by including these directories:

-I ../p4c/backends/ebpf/runtime/ \
-I ../p4c/extensions/p4c-xdp/tests/ \
-I ../p4c/backends/ebpf/runtime/contrib/libbpf/src/ \

Is it really necessary to include them manually or is there something wrong with my install (debian 10, built from sources) annd normally the headers get installed into the system?

Anyway, adding a hint to the Readme would probably be helpful for others.

mihaibudiu commented 3 years ago

This package does not install anything on your system, so you will need to specify the path to the headers.