[kernel]: error: ‘PATH_MAX’ undeclared (first use in this function)

本文介绍了解决Linux内核2.6.18.8版本在交叉编译过程中遇到的关于‘PATH_MAX’未声明的问题。通过检查并添加头文件limits.h解决了编译错误,同时修复了警告信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

内核2.6.18.8交叉编译问题,描述如下:

scripts/mod/sumversion.c: In function ‘get_src_version’:
scripts/mod/sumversion.c:384: error: ‘PATH_MAX’ undeclared (first use
in this function)
scripts/mod/sumversion.c:384: error: (Each undeclared identifier is
reported only once
scripts/mod/sumversion.c:384: error: for each function it appears in.)
scripts/mod/sumversion.c:384: warning: unused variable ‘filelist’
make[3]: *** [scripts/mod/sumversion.o] Error 1
make[2]: *** [scripts/mod] Error 2
make[1]: *** [scripts] Error 2
make[1]: Leaving directory `/home/nios2/uClinux-dist/linux-2.6.x'
make: *** [linux] Error 1

解决方法:

# vi scripts/mod/sumversion.c

头文件包含中查看是否有limits.h,若没有,包含进去即可

#inlcude <limits.h>

使用上面代码编译出现以下问题:make -C ../../ /root/bpf/linux-4.19.90/samples/bpf/ BPF_SAMPLES_PATH=/root/bpf/linux-4.19.90/samples/bpf make[1]: Entering directory '/root/bpf/linux-4.19.90' CALL scripts/checksyscalls.sh DESCEND objtool make -C /root/bpf/linux-4.19.90/samples/bpf/../../tools/lib/bpf/ RM='rm -rf' LDFLAGS= srctree=/root/bpf/linux-4.19.90/samples/bpf/../../ O= Warning: Kernel ABI header at 'tools/include/uapi/linux/bpf.h' differs from latest version at 'include/uapi/linux/bpf.h' HOSTCC /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.o /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c: In function ‘print_violation’: /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:53:26: warning: implicit declaration of function ‘localtime’; did you mean ‘st_atime’? [-Wimplicit-function-declaration] struct tm *tm_info = localtime(&ts); ^~~~~~~~~ st_atime /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:53:26: warning: initialization makes pointer from integer without a cast [-Wint-conversion] /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:55:5: warning: implicit declaration of function ‘strftime’ [-Wimplicit-function-declaration] strftime(time_buf, sizeof(time_buf), "%Y-%m-%d %H:%M:%S", tm_info); ^~~~~~~~ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:55:5: warning: incompatible implicit declaration of built-in function ‘strftime’ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:55:5: note: include ‘<time.h>’ or provide a declaration of ‘strftime’ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c: At top level: /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:69:13: warning: function declaration isn’t a prototype [-Wstrict-prototypes] static void read_violations() { ^~~~~~~~~~~~~~~ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c: In function ‘read_violations’: /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:77:12: error: variable ‘attr’ has initializer but incomplete type struct perf_event_attr attr = { ^~~~~~~~~~~~~~~ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:78:10: error: ‘struct perf_event_attr’ has no member named ‘sample_type’ .sample_type = PERF_SAMPLE_RAW, ^~~~~~~~~~~ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:78:24: error: ‘PERF_SAMPLE_RAW’ undeclared (first use in this function) .sample_type = PERF_SAMPLE_RAW, ^~~~~~~~~~~~~~~ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:78:24: note: each undeclared identifier is reported only once for each function it appears in /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:78:24: warning: excess elements in struct initializer /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:78:24: note: (near initialization for ‘attr’) /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:79:10: error: ‘struct perf_event_attr’ has no member named ‘type’ .type = PERF_TYPE_SOFTWARE, ^~~~ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:79:17: error: ‘PERF_TYPE_SOFTWARE’ undeclared (first use in this function) .type = PERF_TYPE_SOFTWARE, ^~~~~~~~~~~~~~~~~~ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:79:17: warning: excess elements in struct initializer /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:79:17: note: (near initialization for ‘attr’) /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:80:10: error: ‘struct perf_event_attr’ has no member named ‘config’ .config = PERF_COUNT_SW_BPF_OUTPUT, ^~~~~~ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:80:19: error: ‘PERF_COUNT_SW_BPF_OUTPUT’ undeclared (first use in this function) .config = PERF_COUNT_SW_BPF_OUTPUT, ^~~~~~~~~~~~~~~~~~~~~~~~ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:80:19: warning: excess elements in struct initializer /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:80:19: note: (near initialization for ‘attr’) /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:81:10: error: ‘struct perf_event_attr’ has no member named ‘size’ .size = sizeof(attr), ^~~~ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:81:23: error: invalid application of ‘sizeof’ to incomplete type ‘struct perf_event_attr’ .size = sizeof(attr), ^ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:81:17: warning: excess elements in struct initializer .size = sizeof(attr), ^~~~~~ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:81:17: note: (near initialization for ‘attr’) /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:82:10: error: ‘struct perf_event_attr’ has no member named ‘wakeup_events’ .wakeup_events = 1, ^~~~~~~~~~~~~ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:82:26: warning: excess elements in struct initializer .wakeup_events = 1, ^ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:82:26: note: (near initialization for ‘attr’) /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:77:28: error: storage size of ‘attr’ isn’t known struct perf_event_attr attr = { ^~~~ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:85:23: error: ‘__NR_perf_event_open’ undeclared (first use in this function); did you mean ‘bpf_perf_event_ret’? perf_fd = syscall(__NR_perf_event_open, &attr, -1, 0, -1, 0); ^~~~~~~~~~~~~~~~~~~~ bpf_perf_event_ret /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:100:11: warning: implicit declaration of function ‘mmap’ [-Wimplicit-function-declaration] buf = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, perf_fd, 0); ^~~~ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:100:33: error: ‘PROT_READ’ undeclared (first use in this function); did you mean ‘IPPROTO_RAW’? buf = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, perf_fd, 0); ^~~~~~~~~ IPPROTO_RAW /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:100:45: error: ‘PROT_WRITE’ undeclared (first use in this function); did you mean ‘PROT_READ’? buf = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, perf_fd, 0); ^~~~~~~~~~ PROT_READ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:100:57: error: ‘MAP_SHARED’ undeclared (first use in this function) buf = mmap(NULL, mmap_size, PROT_READ | PROT_WRITE, MAP_SHARED, perf_fd, 0); ^~~~~~~~~~ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:101:16: error: ‘MAP_FAILED’ undeclared (first use in this function); did you mean ‘MAP_SHARED’? if (buf == MAP_FAILED) { ^~~~~~~~~~ MAP_SHARED /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:113:55: error: dereferencing pointer to incomplete type ‘struct perf_event_mmap_page’ __u64 data_head = __sync_fetch_and_add(&header->data_head, 0); ^~ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:131:5: warning: implicit declaration of function ‘munmap’ [-Wimplicit-function-declaration] munmap(buf, mmap_size); ^~~~~~ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c: In function ‘load_xdp’: /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:194:15: warning: implicit declaration of function ‘if_nametoindex’ [-Wimplicit-function-declaration] ifindex = if_nametoindex(iface); ^~~~~~~~~~~~~~ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:214:31: warning: implicit declaration of function ‘bpf_object__find_program_by_name’; did you mean ‘bpf_object__find_program_by_title’? [-Wimplicit-function-declaration] prog_fd = bpf_program__fd(bpf_object__find_program_by_name(obj, "xdp_whitelist")); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bpf_object__find_program_by_title /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:214:31: warning: passing argument 1 of ‘bpf_program__fd’ makes pointer from integer without a cast [-Wint-conversion] In file included from /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:11:0: ./tools/lib/bpf/libbpf.h:128:5: note: expected ‘struct bpf_program *’ but argument is of type ‘int’ int bpf_program__fd(struct bpf_program *prog); ^~~~~~~~~~~~~~~ /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c: At top level: /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.c:238:13: warning: function declaration isn’t a prototype [-Wstrict-prototypes] static void unload_xdp() { ^~~~~~~~~~ make[2]: *** [scripts/Makefile.host:107: /root/bpf/linux-4.19.90/samples/bpf/xdp_whitelist_user.o] Error 1 make[1]: *** [Makefile:1695: /root/bpf/linux-4.19.90/samples/bpf/] Error 2 make[1]: Leaving directory '/root/bpf/linux-4.19.90' make: *** [Makefile:224: all] Error 2
最新发布
07-22
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值