You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

编译libbpf及相关工具时出现GElf_Nhdr等类型/函数错误求助

编译libbpf时usdt.c出现GElf_Nhdr未识别及gelf_getnote隐式声明错误

编译libbpf及其相关工具时,编译usdt.c文件出现以下问题:

  • GElf_Nhdr类型未识别
  • gelf_getnote函数隐式声明
  • 所有警告被当作错误处理,最终导致编译失败

系统版本:Linux pegasus 6.4.0-060400-generic x86_64,无法定位问题根源,恳请协助排查。

编译错误信息

pegasus@pegasus:~/Documents/eBPF/libbpf/src$ make
  MKDIR    staticobjs
  CC       staticobjs/bpf.o
  CC       staticobjs/btf.o
  CC       staticobjs/libbpf.o
  CC       staticobjs/libbpf_errno.o
  CC       staticobjs/netlink.o
  CC       staticobjs/nlattr.o
  CC       staticobjs/str_error.o
  CC       staticobjs/libbpf_probes.o
  CC       staticobjs/bpf_prog_linfo.o
  CC       staticobjs/btf_dump.o
  CC       staticobjs/hashmap.o
  CC       staticobjs/ringbuf.o
  CC       staticobjs/strset.o
  CC       staticobjs/linker.o
  CC       staticobjs/gen_loader.o
  CC       staticobjs/relo_core.o
  CC       staticobjs/usdt.o
usdt.c:572:56: error: unknown type name ‘GElf_Nhdr’; did you mean ‘GElf_Shdr’?
  572 | static int parse_usdt_note(Elf *elf, const char *path, GElf_Nhdr *nhdr,
      |                                                        ^~~~~~~~~
      |                                                        GElf_Shdr
usdt.c: In function ‘collect_usdt_targets’:
usdt.c:589:9: error: unknown type name ‘GElf_Nhdr’; did you mean ‘GElf_Shdr’?
  589 |         GElf_Nhdr nhdr;
      |         ^~~~~~~~~
      |         GElf_Shdr
usdt.c:621:23: error: implicit declaration of function ‘gelf_getnote’; did you mean ‘gelf_getsym’? [-Werror=implicit-function-declaration]
  621 |         while ((off = gelf_getnote(data, off, &nhdr, &name_off, &desc_off)) > 0) {
      |                       ^~~~~~~~~~~~
      |                       gelf_getsym
usdt.c:627:23: error: implicit declaration of function ‘parse_usdt_note’; did you mean ‘parse_usdt_spec’? [-Werror=implicit-function-declaration]
  627 |                 err = parse_usdt_note(elf, path, &nhdr, data->d_buf, name_off, desc_off, &note);
      |                       ^~~~~~~~~~~~~~~
      |                       parse_usdt_spec
usdt.c: At top level:
usdt.c:1133:56: error: unknown type name ‘GElf_Nhdr’; did you mean ‘GElf_Shdr’?
 1133 | static int parse_usdt_note(Elf *elf, const char *path, GElf_Nhdr *nhdr,
      |                                                        ^~~~~~~~~
      |                                                        GElf_Shdr
cc1: note: unrecognized command-line option ‘-Wno-unknown-warning-option’ may have been intended to silence earlier diagnostics
cc1: all warnings being treated as errors
make: *** [Makefile:134: staticobjs/usdt.o] Error 1

系统信息

pegasus@pegasus:~/Documents/eBPF/xdp-tutorial$ uname -a
Linux pegasus 6.4.0-060400-generic #202306271339 SMP PREEMPT_DYNAMIC Tue Jun 27 14:26:34 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux

内容的提问来源于stack exchange,提问作者NobinPegasus

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 01:27:54