c - 尝试加载模块,但是当尝试编译模块时,计算机指出几个结构未定义
问题描述
这个模块的目的是基本上做与你在 linux 命令行中键入 cat /proc/buddyinfo 时发生的事情相同的事情
代码
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/mmzone.h>
#define DRIVER_AUTHOR "Matthew James Barnes <mbarnes2k5@Gmail.com>"
#define DRIVER_DESC "A driver that does the same thing as /proc/buddyinfo"
/***
*GLOBAL VARIABLES
***/
extern struct pglist_data *first_online_pgdat(void);
extern struct pglist_data *next_online_pgdat(struct pglist_data*pgdat);
struct pglist_data *pgdat;
extern struct zone *zone;
int init_module(void)
{
int order;
for(pgdat = first_online_pgdat(); pgdat; pgdat = next_online_pgdat(pgdat))
{
for(zone = pgdat->node_zones; zone; zone = next_zone(zone)){
printk(KERN_INFO "Node %d, zone %8s ",pgdat->node_id, zone->name);
printk(KERN_INFO "Node %d", pgdat->node_id);
printk(KERN_CONT "Zone %s",zone->name);
for( order = 0; order < MAX_ORDER; ++order)
printk(KERN_CONT "%6lu ", zone->free_area[order].nr_free);
printk(KERN_CONT "\n");
}
}
return 0;
}
void cleanup_module(void){
printk(KERN_INFO "Zones have been feenished.\n");
}
MODULE_LICENSE("GPL");
MODULE_AUTHOR(DRIVER_AUTHOR);
MODULE_DESCRIPTION(DRIVER_DESC);
~
~
~
~
~
~
~
我决定精简并在我的内核中创建一个 makefile 以及一个名为 module-edits 的文件夹。
在运行 makefile 时的模块编辑中,我遇到了编译错误。
命令行返回以下内容:
make -C /lib/modules/5.4.0-26-generic/build M=/usr/local/share/source_code/version1/module-edits modules
make[1]: Entering directory '/usr/src/linux-headers-5.4.0-26-generic'
Building modules, stage 2.
MODPOST 1 modules
ERROR: "next_online_pgdat" [/usr/local/share/source_code/version1/module-edits/printbuddy.ko] undefined!
ERROR: "next_zone" [/usr/local/share/source_code/version1/module-edits/printbuddy.ko] undefined!
ERROR: "zone" [/usr/local/share/source_code/version1/module-edits/printbuddy.ko] undefined!
ERROR: "first_online_pgdat" [/usr/local/share/source_code/version1/module-edits/printbuddy.ko] undefined!
make[2]: [scripts/Makefile.modpost:94: __modpost] Error 1
make[1]: [Makefile:1632: modules] Error 2
make[1]: Leaving directory '/usr/src/linux-headers-5.4.0-26-generic'
make: [makefile:5: all] Error 2
现在,令人困惑的是,当我输入
#include <linux/mmzone.h>
有许多结构。
pgdat is a struct that allows access to the current page data.
*first_online_pgdat(void); is a function that points to the first page.
*next_online_pgdat(struct pglist_data*pgdat); points to the next page.
struct pglist_data *pgdat;
is basically the representation of my page.
and extern struct zone *zone is the representation of the zone type of the pages.
所有这些都包含在 mmzone 中,但好像 mmzone.h 中的函数甚至没有被引用。
我真的不明白发生了什么,但我会感谢有经验的 linux 程序员的帮助。
解决方案
推荐阅读
- c - 如何在 C 编译时使用外部数组的大小?
- java - Java URIBuilder 位于加载程序“app”的未命名模块中
- c++ - X 的错误声明抛出不同的异常
- c# - 模型完成后,我的 ML 程序输出是否继续从我给他的输入中学习?
- mysql - 当 index.js 有“require('mysql2');”时,“分配失败 - 进程内存不足”
- r - 如果我从 R 控制台将程序作为脚本运行,parLapply 真的很慢,但如果我在 rstudio 中逐行运行我的代码,则非常快
- amazon-web-services - 图片不使用heroku显示??亚马逊 S3
- flutter - 在颤动中处理实体初始值的最佳方法是什么
- nuxt.js - 放大到大屏时如何防止 Nuxt Vuetify NavigationDrawer 出现?
- python - 计算和测量气泡的高度