Skip to content

Commit 5273b61

Browse files
Make libbpf headers possible to include
1 parent 057d0be commit 5273b61

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

CMakeLists.txt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,20 @@ elseif(${CMAKE_SYSTEM_PROCESSOR} MATCHES "loongarch64")
3535
set(ARCH "loongarch")
3636
endif()
3737

38-
set(LIBBPF_INCLUDE_DIRS ${CMAKE_CURRENT_BINARY_DIR}/libbpf)
38+
set(LIBBPF_INCLUDE_DIRS
39+
${CMAKE_CURRENT_BINARY_DIR}/libbpf
40+
${CMAKE_CURRENT_SOURCE_DIR}/libbpf/include
41+
${CMAKE_CURRENT_BINARY_DIR}/libbpf/usr/include)
3942
set(LIBBPF_LIBRARIES ${CMAKE_CURRENT_BINARY_DIR}/libbpf/libbpf.a)
4043

4144
# EXAMPLE_VERSION_INFO is defined by setup.py and passed into the C++ code as a
4245
# define (VERSION_INFO) here.
4346
target_compile_definitions(pylibbpf
4447
PRIVATE VERSION_INFO=${PYLIBBPF_VERSION_INFO})
48+
49+
# ensure build order
50+
add_dependencies(pylibbpf libbpf)
51+
52+
# headers + linking
53+
target_include_directories(pylibbpf PRIVATE ${LIBBPF_INCLUDE_DIRS})
54+
target_link_libraries(pylibbpf PRIVATE ${LIBBPF_LIBRARIES})

src/main.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
#include <pybind11/pybind11.h>
2-
32
#define STRINGIFY(x) #x
43
#define MACRO_STRINGIFY(x) STRINGIFY(x)
54

5+
extern "C" {
6+
#include "bpf/libbpf.h"
7+
}
8+
69
int add(int i, int j) {
710
return i + j;
811
}

0 commit comments

Comments
 (0)