|
一个模块编程的例子,还是网上找的,怎么也搞不定
如下:
[code:1]
#include <linux/init.h>
#include <linux/kernel.h> /* 我们正在干一些关于内核的事情 */
#include <linux/module.h> /* 具体来说,是在写一个模块 */
#if CONFIG_MODVERSIONS==1 /* 如果需要指明模块的版本的话 */
#define MODVERSIONS
#include <linux/modversions.h> /* 那就将linux/modversions.h文件包含*/
#endif
int init_module() /* 模块初始化函数 */
{
printk("Hello, this is the kernel speaking!\n");
/* 如果我们将返回值置为非零,这说明初始化模块失败 */
return 0;
}
void cleanup_module() /* 模块卸载函数 */
{
printk("This kernel module has been removed.\n");
}
[/code:1]
Makefile:
[code:1]
CC=gcc
MODCFLAGS := -Wall -DMODULE -D__KERNEL__ -DLINUX -I/usr/src/linux/include
hello.o: hello.c
$(CC) $(MODCFLAGS) -c hello.c
[/code:1]
编译错误:
[code:1]
[yanc@yan module]$ make
gcc -Wall -DMODULE -D__KERNEL__ -DLINUX -I/usr/src/linux/include -c hello.c
In file included from /usr/src/linux/include/linux/rwsem.h:27,
from /usr/src/linux/include/asm/semaphore.h:42,
from /usr/src/linux/include/linux/sched.h:20,
from /usr/src/linux/include/linux/module.h:10,
from hello.c:2:
/usr/src/linux/include/asm/rwsem.h: 在函数 ‘__down_read’ 中:
/usr/src/linux/include/asm/rwsem.h:105: 错误:expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
/usr/src/linux/include/asm/rwsem.h: 在函数 ‘__down_write’ 中:
/usr/src/linux/include/asm/rwsem.h:157: 错误:expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
/usr/src/linux/include/asm/rwsem.h: 在函数 ‘__up_read’ 中:
/usr/src/linux/include/asm/rwsem.h:194: 错误:expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
/usr/src/linux/include/asm/rwsem.h:188: 警告:未使用的变量 ‘tmp’
/usr/src/linux/include/asm/rwsem.h: 在函数 ‘__up_write’ 中:
/usr/src/linux/include/asm/rwsem.h:220: 错误:expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
/usr/src/linux/include/asm/rwsem.h: 在函数 ‘__downgrade_write’ 中:
/usr/src/linux/include/asm/rwsem.h:245: 错误:expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
In file included from /usr/src/linux/include/linux/sched.h:20,
from /usr/src/linux/include/linux/module.h:10,
from hello.c:2:
/usr/src/linux/include/asm/semaphore.h: 在函数 ‘down’ 中:
/usr/src/linux/include/asm/semaphore.h:105: 错误:expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
/usr/src/linux/include/asm/semaphore.h: 在函数 ‘down_interruptible’ 中:
/usr/src/linux/include/asm/semaphore.h:130: 错误:expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
/usr/src/linux/include/asm/semaphore.h: 在函数 ‘down_trylock’ 中:
/usr/src/linux/include/asm/semaphore.h:155: 错误:expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
/usr/src/linux/include/asm/semaphore.h: 在函数 ‘up’ 中:
/usr/src/linux/include/asm/semaphore.h:179: 错误:expected ‘:’ or ‘)’ before ‘KBUILD_BASENAME’
在包含自 hello.c:7 的文件中:
/usr/include/linux/modversions.h:1:2: 错误:#error Modules should never use kernel-headers system headers,
/usr/include/linux/modversions.h:2:2: 错误:#error but rather headers from the appropriate kernel package.
/usr/include/linux/modversions.h:3:2: 错误:#error Change -I/usr/src/linux/include (or similar) to
/usr/include/linux/modversions.h:4:2: 错误:#error -I/lib/modules/$(uname -r)/build/include
/usr/include/linux/modversions.h:5:2: 错误:#error to build against the currently-running kernel.
make: *** [hello.o] 错误 1
[yanc@yan module]$
[/code:1]
大哥们帮忙,指导小弟一下吧~ |
|