aquasecurity / libbpfgo

eBPF library for Go. Powered by libbpf.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

could not determine kind of name for C.bpf_map__lookup_elem

Jun10ng opened this issue · comments

Hi masters,

I am trying to write a simple "perf" program. But I have a build-failed issue when I compile it. I google it but there is nothing useful.
I kindly for your help, tks.

The error is /go_workshop/pkg/mod/github.com/aquasecurity/libbpfgo@v0.3.0-libbpf-0.8.0/libbpfgo.go:707:10: could not determine kind of name for C.bpf_map__lookup_elem

the full fail make log output:

make -C . main
make[1]: Entering directory '/vagrant/perf'
mkdir -p ./output/libbpf
CC="gcc" CFLAGS="-ggdb -gdwarf -O2 -Wall -fpie -Wno-unused-variable -Wno-unused-function" LD_FLAGS="" \
   make -C /vagrant/libbpf/src \
        BUILD_STATIC_ONLY=1 \
        OBJDIR=/vagrant/perf/output/libbpf \
        DESTDIR=/vagrant/perf/output \
        INCLUDEDIR= LIBDIR= UAPIDIR= prefix= libdir= install
make[2]: Entering directory '/vagrant/libbpf/src'
  MKDIR    /vagrant/perf/output/libbpf/staticobjs
  CC       /vagrant/perf/output/libbpf/staticobjs/bpf.o
  CC       /vagrant/perf/output/libbpf/staticobjs/btf.o
  CC       /vagrant/perf/output/libbpf/staticobjs/libbpf.o
  CC       /vagrant/perf/output/libbpf/staticobjs/libbpf_errno.o
  CC       /vagrant/perf/output/libbpf/staticobjs/netlink.o
  CC       /vagrant/perf/output/libbpf/staticobjs/nlattr.o
  CC       /vagrant/perf/output/libbpf/staticobjs/str_error.o
  CC       /vagrant/perf/output/libbpf/staticobjs/libbpf_probes.o
  CC       /vagrant/perf/output/libbpf/staticobjs/bpf_prog_linfo.o
  CC       /vagrant/perf/output/libbpf/staticobjs/xsk.o
  CC       /vagrant/perf/output/libbpf/staticobjs/btf_dump.o
  CC       /vagrant/perf/output/libbpf/staticobjs/hashmap.o
  CC       /vagrant/perf/output/libbpf/staticobjs/ringbuf.o
  CC       /vagrant/perf/output/libbpf/staticobjs/strset.o
  CC       /vagrant/perf/output/libbpf/staticobjs/linker.o
  CC       /vagrant/perf/output/libbpf/staticobjs/gen_loader.o
  CC       /vagrant/perf/output/libbpf/staticobjs/relo_core.o
  AR       /vagrant/perf/output/libbpf/libbpf.a
  INSTALL  bpf.h libbpf.h btf.h libbpf_common.h libbpf_legacy.h xsk.h bpf_helpers.h bpf_helper_defs.h bpf_tracing.h bpf_endian.h bpf_core_read.h skel_internal.h libbpf_version.h
  INSTALL  /vagrant/perf/output/libbpf/libbpf.pc
  INSTALL  /vagrant/perf/output/libbpf/libbpf.a 
make[2]: Leaving directory '/vagrant/libbpf/src'
INFO: generating vmlinux.h from /sys/kernel/btf/vmlinux
clang -ggdb -gdwarf -O2 -Wall -fpie -Wno-unused-variable -Wno-unused-function -target bpf -D__TARGET_ARCH_x86 -I. -I./output -c main.bpf.c -o main.bpf.o
CC=clang \
        CGO_CFLAGS="-I/vagrant/perf/output" \
        CGO_LDFLAGS="-lelf -lz /vagrant/perf/output/libbpf.a" \
                GOARCH=amd64 \
                go build \
                -tags netgo -ldflags '-w -extldflags "-static"' \
                -o main ./main.go
# github.com/aquasecurity/libbpfgo
/go_workshop/pkg/mod/github.com/aquasecurity/libbpfgo@v0.3.0-libbpf-0.8.0/libbpfgo.go:707:10: could not determine kind of name for C.bpf_map__lookup_elem
make[1]: *** [Makefile:109: main] Error 2
make[1]: Leaving directory '/vagrant/perf'
make: *** [Makefile:47: all] Error 2

My virtual box(vagrant) is "ubuntu/jammy64"
libbpf-go version is v0.3.0-libbpf-0.8.0

main.go:
https://gist.github.com/Jun10ng/95ed54f615fda984218aafc3df75e0dd

main.bpf.c
https://gist.github.com/Jun10ng/ed0b28040bbd8b0db341c8205ad0ca73

main.bpf.h
https://gist.github.com/Jun10ng/2fcd11959ac04936f12507e9c157f4f1

Makefile
https://gist.github.com/Jun10ng/a5c05c38c23c490249a9827854a30c7a

My bad, I use a wrong version, I fixed it after update libbpf and libbpfgo by git submodule update --remote.