PF_RING
PF_RING copied to clipboard
Undefined Reference on Ubuntu 23.10
Hello
I'm in the process of integrating the PF_RING library into a CMake project, but I'm facing compilation errors. I've followed the steps described in this guide to install PF_RING.
Please let me know if you need more information. P.S.: I didn't have any issues installing the PF_RING library, and compiling the examples
Environment:
> cat /etc/os-release
PRETTY_NAME="Ubuntu 23.10"
NAME="Ubuntu"
VERSION_ID="23.10"
VERSION="23.10 (Mantic Minotaur)"
VERSION_CODENAME=mantic
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=mantic
LOGO=ubuntu-logo
> cat /sys/firmware/devicetree/base/model
Raspberry Pi 4 Model B Rev 1.5
> uname -r
6.5.0-1006-raspi
> lscpu
Architecture: aarch64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Vendor ID: ARM
Model name: Cortex-A72
Model: 3
Thread(s) per core: 1
Core(s) per cluster: 4
Socket(s): -
Cluster(s): 1
Stepping: r0p3
CPU(s) scaling MHz: 83%
CPU max MHz: 1800.0000
CPU min MHz: 600.0000
BogoMIPS: 108.00
Flags: fp asimd evtstrm crc32 cpuid
Caches (sum of all):
L1d: 128 KiB (4 instances)
L1i: 192 KiB (4 instances)
L2: 1 MiB (1 instance)
Vulnerabilities:
Gather data sampling: Not affected
Itlb multihit: Not affected
L1tf: Not affected
Mds: Not affected
Meltdown: Not affected
Mmio stale data: Not affected
Retbleed: Not affected
Spec rstack overflow: Not affected
Spec store bypass: Vulnerable
Spectre v1: Mitigation; __user pointer sanitization
Spectre v2: Vulnerable
Srbds: Not affected
Tsx async abort: Not affected
Compilation errors:
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring.o): in function `pfring_loop':
pfring.c:(.text+0x2a0): undefined reference to `bpf_filter'
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring.o): in function `pfring_send':
pfring.c:(.text+0x658): undefined reference to `bpf_filter'
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring.o): in function `pfring_recv':
pfring.c:(.text+0x794): undefined reference to `bpf_filter'
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring_mod.o): in function `pfring_mod_set_bpf_filter':
pfring_mod.c:(.text+0x1a3c): undefined reference to `pcap_open_dead'
/usr/bin/ld: pfring_mod.c:(.text+0x1a98): undefined reference to `pcap_compile'
/usr/bin/ld: pfring_mod.c:(.text+0x1aa4): undefined reference to `pcap_close'
/usr/bin/ld: pfring_mod.c:(.text+0x1ae4): undefined reference to `pcap_freecode'
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring_utils.o): in function `pfring_parse_bpf_filter':
pfring_utils.c:(.text+0x1838): undefined reference to `pcap_compile_nopcap'
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring_utils.o): in function `pfring_free_bpf_filter':
pfring_utils.c:(.text+0x1870): undefined reference to `pcap_freecode'
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring_utils.o): in function `pfring_bpf_filter':
pfring_utils.c:(.text+0x1874): undefined reference to `bpf_filter'
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring_mod_pcap.o): in function `pfring_mod_pcap_close':
pfring_mod_pcap.c:(.text+0x54): undefined reference to `pcap_close'
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring_mod_pcap.o): in function `pfring_mod_pcap_recv':
pfring_mod_pcap.c:(.text+0x218): undefined reference to `pcap_next'
/usr/bin/ld: pfring_mod_pcap.c:(.text+0x294): undefined reference to `pcap_next_ex'
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring_mod_pcap.o): in function `pfring_mod_pcap_set_bpf_filter':
pfring_mod_pcap.c:(.text+0x398): undefined reference to `pcap_compile'
/usr/bin/ld: pfring_mod_pcap.c:(.text+0x3a8): undefined reference to `pcap_setfilter'
/usr/bin/ld: pfring_mod_pcap.c:(.text+0x3b4): undefined reference to `pcap_freecode'
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring_mod_pcap.o): in function `pfring_mod_pcap_open':
pfring_mod_pcap.c:(.text+0x4b0): undefined reference to `pcap_open_offline'
/usr/bin/ld: pfring_mod_pcap.c:(.text+0x4bc): undefined reference to `pcap_get_selectable_fd'
/usr/bin/ld: pfring_mod_pcap.c:(.text+0x518): undefined reference to `pcap_open_offline'
/usr/bin/ld: pfring_mod_pcap.c:(.text+0x538): undefined reference to `pcap_open_live'
/usr/bin/ld: pfring_mod_pcap.c:(.text+0x544): undefined reference to `pcap_get_selectable_fd'
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring_mod_pcap.o): in function `pfring_mod_pcap_stats':
pfring_mod_pcap.c:(.text+0x5ac): undefined reference to `pcap_stats'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/test.dir/build.make:98: test] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/test.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
raspberry1@raspberry1:~/Documents/kevin/test$ sudo make
[ 50%] Linking CXX executable test
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring.o): in function `pfring_loop':
pfring.c:(.text+0x2a0): undefined reference to `bpf_filter'
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring.o): in function `pfring_send':
pfring.c:(.text+0x658): undefined reference to `bpf_filter'
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring.o): in function `pfring_recv':
pfring.c:(.text+0x794): undefined reference to `bpf_filter'
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring_mod.o): in function `pfring_mod_set_bpf_filter':
pfring_mod.c:(.text+0x1a3c): undefined reference to `pcap_open_dead'
/usr/bin/ld: pfring_mod.c:(.text+0x1a98): undefined reference to `pcap_compile'
/usr/bin/ld: pfring_mod.c:(.text+0x1aa4): undefined reference to `pcap_close'
/usr/bin/ld: pfring_mod.c:(.text+0x1ae4): undefined reference to `pcap_freecode'
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring_utils.o): in function `pfring_parse_bpf_filter':
pfring_utils.c:(.text+0x1838): undefined reference to `pcap_compile_nopcap'
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring_utils.o): in function `pfring_free_bpf_filter':
pfring_utils.c:(.text+0x1870): undefined reference to `pcap_freecode'
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring_utils.o): in function `pfring_bpf_filter':
pfring_utils.c:(.text+0x1874): undefined reference to `bpf_filter'
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring_mod_pcap.o): in function `pfring_mod_pcap_close':
pfring_mod_pcap.c:(.text+0x54): undefined reference to `pcap_close'
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring_mod_pcap.o): in function `pfring_mod_pcap_recv':
pfring_mod_pcap.c:(.text+0x218): undefined reference to `pcap_next'
/usr/bin/ld: pfring_mod_pcap.c:(.text+0x294): undefined reference to `pcap_next_ex'
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring_mod_pcap.o): in function `pfring_mod_pcap_set_bpf_filter':
pfring_mod_pcap.c:(.text+0x398): undefined reference to `pcap_compile'
/usr/bin/ld: pfring_mod_pcap.c:(.text+0x3a8): undefined reference to `pcap_setfilter'
/usr/bin/ld: pfring_mod_pcap.c:(.text+0x3b4): undefined reference to `pcap_freecode'
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring_mod_pcap.o): in function `pfring_mod_pcap_open':
pfring_mod_pcap.c:(.text+0x4b0): undefined reference to `pcap_open_offline'
/usr/bin/ld: pfring_mod_pcap.c:(.text+0x4bc): undefined reference to `pcap_get_selectable_fd'
/usr/bin/ld: pfring_mod_pcap.c:(.text+0x518): undefined reference to `pcap_open_offline'
/usr/bin/ld: pfring_mod_pcap.c:(.text+0x538): undefined reference to `pcap_open_live'
/usr/bin/ld: pfring_mod_pcap.c:(.text+0x544): undefined reference to `pcap_get_selectable_fd'
/usr/bin/ld: /usr/local/lib/libpfring.a(pfring_mod_pcap.o): in function `pfring_mod_pcap_stats':
pfring_mod_pcap.c:(.text+0x5ac): undefined reference to `pcap_stats'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/test.dir/build.make:98: test] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/test.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
CMake file:
cmake_minimum_required(VERSION 2.8)
project(test C CXX)
set(BIN test)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++11 -Os -g")
set(REQUIRED_LIBRARIES
rt
pcap
curl
pthread
nsl
dl
nl-genl-3
nl-3)
include_directories(
${CMAKE_CURRENT_SOURCE_DIR}/include/)
file(GLOB_RECURSE INC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/include/*.*)
file(GLOB_RECURSE SRC_FILES ${CMAKE_CURRENT_SOURCE_DIR}/src/*.cpp)
ADD_LIBRARY(pfring_lib STATIC IMPORTED)
SET_TARGET_PROPERTIES(pfring_lib PROPERTIES IMPORTED_LOCATION /usr/local/lib/libpfring.a)
add_executable(${BIN} ${INC_FILES} ${SRC_FILES})
target_link_libraries(${BIN} ${REQUIRED_LIBRARIES}
"-Wl,--whole-archive" pfring_lib "-Wl,--no-whole-archive")
I am not a cmake expert, however I see compilation is failing because it cannot find symbols from libpcap
Hi @cardigliano
Before creating this issue, I tried with a static link to libpcap, and encountered the same error. I've just identified the problem, it's related to the nl libraries. CMake can't locate the libraries on the Raspberry Pi, so I had to add a static link to where these libraries are located. However, now I'm getting the following error:
[ 50%] Building CXX object CMakeFiles/test.dir/src/main.cpp.o
In file included from /usr/include/linux/posix_types.h:5,
from /usr/include/asm-generic/socket.h:5,
from /usr/include/aarch64-linux-gnu/asm/socket.h:1,
from /usr/include/aarch64-linux-gnu/bits/socket.h:385,
from /usr/include/aarch64-linux-gnu/sys/socket.h:33,
from /usr/local/include/pfring.h:41,
from /home/raspberry1/Documents/kevin/test/src/main.cpp:3:
/usr/include/linux/if_packet.h:24:17: error: flexible array member ‘sockaddr_ll::<unnamed union>::<unnamed struct>::sll_addr_flex’ not at end of ‘struct __pfring’
24 | __DECLARE_FLEX_ARRAY(unsigned char, sll_addr_flex);
| ^~~~~~~~~~~~~~~~~~~~
/usr/local/include/pfring.h:364:11: note: next member ‘pfring* __pfring::reflector_socket’ declared here
364 | pfring *reflector_socket;
| ^~~~~~~~~~~~~~~~
/usr/local/include/pfring.h:193:8: note: in the definition of ‘struct __pfring’
193 | struct __pfring {
| ^~~~~~~~
make[2]: *** [CMakeFiles/test.dir/build.make:76: CMakeFiles/test.dir/src/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/Makefile2:83: CMakeFiles/test.dir/all] Error 2
make: *** [Makefile:91: all] Error 2
Regards!
Hi @cardigliano
Sorry for not updating the thread earlier, but I have already fixed the issue. The problem was due to some paths related to the Raspberry Pi architecture not being in the default directory for CMake, which caused the conflicts mentioned in my previous message
Thank you
Thank you for the update