- 论坛徽章:
- 0
|
初学Linux下的模块编程,从网上找了一些资料照着做。但是在编译时出现一大堆错误或警告信息。
代码如下:
#include <linux/kernel.h>;/* 我们在做内核的工作 */
#include <linux/module.h>;/* 明确的,一个模块 */
/* 处理 CONFIG_MODVERSIONS */
#if CONFIG_MODVERSIONS==1
#define MODVERSIONS
#include
#endif
/* 初始化模块 */
int init_module()
{
printk("Hello, world - this is the kernel speaking\n" ;
/* 如果我们返回一个非零值, 那就意味着
* init_module 初始化失败并且内核模块
* 不能加载 */
return 0;
}
/* Cleanup - 撤消 init_module 所做的任何事情 */
void cleanup_module()
{
printk("Short is the life of a kernel module\n" ;
}
编译命令是:gcc -Wall -DMODULE -D__KERNEL__ -DLINUX -c hello.c
请问是因为什么原因呢?因为错误提示太多,没有列出。估计可能是头文件出的问题。 |
|