|
刚开始学习内核, 我的模块文件hello.c
/*
* Hello world module.
*/
#include <linux/module.h>
#if defined(CONFIG_SMP)
#define __SMP__
#endif
#if defined(CONFIG_MODVERSIONS)
#define MODVERSIONS
#include <linux/modversions.h>
#endif
#include <linux/kernel.h>
int init_module(void)
{
printk(KERN_DEBUG "Hello, kernel!\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_DEBUG "Good-bye, kernel!\n");
}
编译明令gcc -D__KERNEL__ -I/usr/include -DMODULE -Wall -O2 -c -o hello.o hello.c
结果报错:In file included from /usr/include/linux/module.h:10,
from hello.c:4:
/usr/include/linux/config.h:5:2: #error Incorrectly using glibc headers for a kernel module
hello.c: In function `init_module':
hello.c:19: warning: implicit declaration of function `printk'
hello.c:19: error: `KERN_DEBUG' undeclared (first use in this function)
hello.c:19: error: (Each undeclared identifier is reported only once
hello.c:19: error: for each function it appears in.)
hello.c:19: error: syntax error before string constant
hello.c: In function `cleanup_module':
hello.c:25: error: `KERN_DEBUG' undeclared (first use in this function)
hello.c:25: error: syntax error before string constant
请问什么原因,谢谢 |
|