编译内核模块 .ko文件的注意事项 缺少:mmzone.h bounds.h

本文详细介绍了在独立内核目录外编译模块时遇到的头文件缺失问题,以及如何通过避免使用make clean或执行make prepare来解决这一问题。通过确保内核源代码树经过make过程,可以防止生成的关键头文件被清除,从而顺利编译模块。

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

前两天新到手一个6410的板子,按照说明在上面跑了一下android和QT,都成了。今天想试试helloworld模块的装载发现了一些需要注意的问题。

出现的问题:编译的时候提示缺少头文件 mmzone.h ....bounds.h...等

include/linux/mmzone.h:18:26: error: linux/bounds.h: No such file or directory
include/linux/mmzone.h:197:5: warning: "MAX_NR_ZONES" is not defined

原因:bounds.h是在编译内核时生成的,类似于编译产生的.o文件,如果你运行

"make clean" or "make distclean",这个文件就会被清除掉(详情查看内核Makefile)。因此,如果再利用此内核源码编译内核模块,
如果有涉及bounds.h,就会出现找不到该文件的错误。

解决:独立内核目录之外编译模块时,要确保makefile文件中所定义的内核源代码树已经make过一遍,且没有make  clean。这样就不会清除生成的bound.h头文件,这个文件是生成模块必须的。

或者"make prepare"

这样就会重新生成bounds.h,搞定了!

再看看其内容:


#ifndef __LINUX_BOUNDS_H__
#define __LINUX_BOUNDS_H__
/*
 * DO NOT MODIFY.
 *
 * This file was generated by Kbuild
 *
 */

#define NR_PAGEFLAGS 19 /* __NR_PAGEFLAGS @ */
#define MAX_NR_ZONES 3 /* __MAX_NR_ZONES @ */

#endif
转载:http://blog.chinaunix.net/space.php?uid=25115736&do=blog&id=2512075
/home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/mm/vmscan.c:431:13: error: static declaration of 'cgroup_reclaim' follows non-static declaration static bool cgroup_reclaim(struct scan_control *sc) ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/include/linux/swap.h:423:13: note: previous declaration is here extern bool cgroup_reclaim(struct scan_control *sc); ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/mm/vmscan.c:449:13: error: static declaration of 'writeback_throttling_sane' follows non-static declaration static bool writeback_throttling_sane(struct scan_control *sc) ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/include/linux/swap.h:427:13: note: previous declaration is here extern bool writeback_throttling_sane(struct scan_control *sc); ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/mm/vmscan.c:591:22: error: static declaration of 'lruvec_lru_size' follows non-static declaration static unsigned long lruvec_lru_size(struct lruvec *lruvec, enum lru_list lru, ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/include/linux/mmzone.h:1205:22: note: previous declaration is here extern unsigned long lruvec_lru_size(struct lruvec *lruvec, enum lru_list lru, int zone_idx); ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/mm/vmscan.c:891:22: error: static declaration of 'shrink_slab' follows non-static declaration static unsigned long shrink_slab(gfp_t gfp_mask, int nid, ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/include/linux/swap.h:425:22: note: previous declaration is here extern unsigned long shrink_slab(gfp_t gfp_mask, int nid, struct mem_cgroup *memcg, ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/mm/vmscan.c:2224:12: error: static declaration of 'current_may_throttle' follows non-static declaration static int current_may_throttle(void) ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/include/linux/swap.h:432:12: note: previous declaration is here extern int current_may_throttle(void); ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/mm/vmscan.c:2497:22: error: static declaration of 'shrink_list' follows non-static declaration static unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan, ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/include/linux/swap.h:419:22: note: previous declaration is here extern unsigned long shrink_list(enum lru_list lru, unsigned long nr_to_scan, ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/mm/vmscan.c:2539:13: error: static declaration of 'inactive_is_low' follows non-static declaration static bool inactive_is_low(struct lruvec *lruvec, enum lru_list inactive_lru) ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/include/linux/swap.h:422:13: note: previous declaration is here extern bool inactive_is_low(struct lruvec *lruvec, enum lru_list inactive_lru); ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/mm/vmscan.c:4261:12: error: static declaration of 'kswapd' follows non-static declaration static int kswapd(void *p) ^ /home/lhl/ga-4.1/repo_code/out/oriole/kernel/src_tmp/linux-5.15/include/linux/swap.h:37:5: note: previous declaration is here int kswapd (void *p); ^
07-19
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值