我没有获得此代码的输出。我的Makefile需要做些什么改变? 代码:
#define MODULE
#define LINUX
#define __KERNEL__
#include<linux/module.h>
#include<linux/kernel.h>
#include<linux/init.h>``
MODULE_LISENCE("GPL");
MODULE_AUTHOR("Peter Jay Salzman");
static u8 (mybyte='A');
static int (myint='i');
MODULE_PARM(mybyte, "b");
MODULE_PARM(myint, "i");
MODULE_PARM_DESC(mybyte, "this cannot do anything\n");
static int __init hello5_init(void)
{
printk("my byte %i\n",mybyte);
printk("my integer %i \n",myint);
}
static void __exit hello5_exit()
{
printk("bye world\n");
}
module_init(hell05_init);
module_exit(helo5_exit);
生成文件: obj-m + = hello5.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
exit:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
.PHONY: all, exit
错误:
/home/kumarmagi/Desktop/amit/hello5/hello5.c:23:24: error: ‘mybyte’ undeclared (first use in this function)
/home/kumarmagi/Desktop/amit/hello5/hello5.c:23:24: note: each undeclared identifier is reported only once for each function it appears in
/home/kumarmagi/Desktop/amit/hello5/hello5.c:24:28: error: ‘myint’ undeclared (first use in this function)
/home/kumarmagi/Desktop/amit/hello5/hello5.c:25:1: warning: no return statement in function returning non-void [-Wreturn-type]
答案 0 :(得分:0)
尝试改变:
MODULE_PARM(mybyte, "b");
MODULE_PARM(myint, "i");
static int (myint='i');
static u8 (mybyte='A');
为:
module_param(mybyte, short, 0660);
module_param(myint, int, 0660);
static short mybyte='A';
static int myint='i';