当前位置: 技术问答>linux和unix
编译最简单的 hello world 模块出错,郁闷了,大家帮我来看看吧
来源: 互联网 发布时间:2016-02-29
本文导语: 刚自学linux驱动,对照着linux设备驱动程序(第三版)写了个hello world 就出错~~严重打击啊~各位大虾帮我看下 ~~谢谢了 内核版本:2.6.15 用的系统是ubuntu的 hello world代码是 #include #include #include MODULE_LICEN...
刚自学linux驱动,对照着linux设备驱动程序(第三版)写了个hello world 就出错~~严重打击啊~各位大虾帮我看下 ~~谢谢了
内核版本:2.6.15
用的系统是ubuntu的
hello world代码是
#include
#include
#include
MODULE_LICENSE("GPL");// 新,否则有 waring, 去掉了 #define MODULE, 自动定义
static int hello_init(void)
{
printk(KERN_ALERT "Hello, worldn");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel worldn");
}
module_init(hello_init);// 必须!!
module_exit(hello_exit); // 必须!!
Makefile里面就一句
obj-m := hello.o
#make -C /usr/src/linux-source-2.6.15 SUBDIRS=$PWD modules
然后就出现一大堆错误~~
出现的错误太多了 ~~COPY了前面几行和后面几行,太多了显示不下~中没有全部COPY下来,大家帮我看下吧~~谢谢了
/******************************************************************************************/
make: Entering directory `/usr/src/linux-source-2.6.15'
Makefile:490: .config: No such file or directory
WARNING: Symbol version dump /usr/src/linux-source-2.6.15/Module.symvers
is missing; modules will have no dependencies and modversions.
CC [M] /home/wyc/drivers/hello.o
cc1: error: include/linux/autoconf.h: No such file or directory
In file included from include/linux/module.h:9,
from /home/wyc/drivers/hello.c:1:
include/linux/config.h:6:28: error: linux/autoconf.h: No such file or directory
In file included from include/linux/module.h:10,
from /home/wyc/drivers/hello.c:1:
include/linux/sched.h:4:36: error: asm/param.h: No such file or directory
In file included from include/linux/posix_types.h:47,
from include/linux/types.h:14,
from include/linux/capability.h:16,
from include/linux/sched.h:7,
from include/linux/module.h:10,
from /home/wyc/drivers/hello.c:1:
/usr/lib/gcc/i486-linux-gnu/4.0.3/include/asm/posix_types.h:13:22: error: features.h: No such file or directory
/usr/lib/gcc/i486-linux-gnu/4.0.3/include/asm/posix_types.h:14:35: error: no include path in which to search for asm/posix_types.h
In file included from include/linux/capability.h:16,
from include/linux/sched.h:7,
from include/linux/module.h:10,
from /home/wyc/drivers/hello.c:1:
include/linux/types.h:15:23: error: asm/types.h: No such file or directory
In file included from include/linux/capability.h:16,
from include/linux/sched.h:7,
from include/linux/module.h:10,
from /home/wyc/drivers/hello.c:1:
..........................
.........................帖子太长,不让我递交,中间的 只好略过了
........................
include/linux/kobject.h:33: 警告: 数据定义时没有类型或存储类
include/linux/kobject.h:38: 错误: 字段 ‘kref’ 的类型不完全
include/linux/kobject.h:153: 错误: 字段 ‘rwsem’ 的类型不完全
include/linux/kobject.h:236: 错误: 字段 ‘attr’ 的类型不完全
include/linux/kobject.h:237: 错误: syntax error before ‘ssize_t’
include/linux/kobject.h:237: 警告: 结构或联合后没有分号
include/linux/kobject.h:238: 错误: syntax error before ‘*’ token
include/linux/kobject.h:238: 错误: syntax error before ‘size_t’
include/linux/kobject.h:238: 警告: 在 ‘ssize_t’ 的声明中,类型默认为 ‘int’
include/linux/kobject.h:238: 警告: 函数声明不是一个原型
include/linux/kobject.h:238: 错误: ‘ssize_t’ 声明为返回一个函数的函数
include/linux/kobject.h:238: 警告: 函数声明不是一个原型
include/linux/kobject.h:238: 错误: ‘ssize_t’ 被重新声明为不同意义的符号
include/linux/types.h:70: 错误: ‘ssize_t’ 的上一个声明在此
include/linux/kobject.h:238: 警告: 数据定义时没有类型或存储类
In file included from /home/wyc/drivers/hello.c:1:
include/linux/module.h:21:23: error: asm/local.h: No such file or directory
include/linux/module.h:23:24: error: asm/module.h: No such file or directory
In file included from /home/wyc/drivers/hello.c:1:
include/linux/module.h:50: 错误: 字段 ‘attr’ 的类型不完全
include/linux/module.h:51: 错误: syntax error before ‘ssize_t’
include/linux/module.h:51: 警告: 结构或联合后没有分号
include/linux/module.h:52: 错误: syntax error before ‘*’ token
include/linux/module.h:53: 错误: syntax error before ‘size_t’
include/linux/module.h:53: 警告: 在 ‘ssize_t’ 的声明中,类型默认为 ‘int’
include/linux/module.h:53: 警告: 函数声明不是一个原型
include/linux/module.h:53: 错误: ‘ssize_t’ 声明为返回一个函数的函数
include/linux/module.h:53: 警告: 函数声明不是一个原型
include/linux/module.h:53: 错误: ‘ssize_t’ 被重新声明为不同意义的符号
include/linux/types.h:70: 错误: ‘ssize_t’ 的上一个声明在此
include/linux/module.h:53: 警告: 数据定义时没有类型或存储类
include/linux/module.h:57: 错误: syntax error before ‘}’ token
/home/wyc/drivers/hello.c:2:27: error: linux/config.h: No such file or directory
/home/wyc/drivers/hello.c:15: 致命错误: 打开依赖文件 /home/wyc/drivers/.hello.o.d:Permission denied
编译中断。
make[1]: *** [/home/wyc/drivers/hello.o] 错误 1
make: *** [_module_/home/wyc/drivers] 错误 2
make: Leaving directory `/usr/src/linux-source-2.6.15'
/**********************************************************************************************/
不知道是代码错误还是我有什么地方配置错误了,大家帮 我 看看吧
内核版本:2.6.15
用的系统是ubuntu的
hello world代码是
#include
#include
#include
MODULE_LICENSE("GPL");// 新,否则有 waring, 去掉了 #define MODULE, 自动定义
static int hello_init(void)
{
printk(KERN_ALERT "Hello, worldn");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel worldn");
}
module_init(hello_init);// 必须!!
module_exit(hello_exit); // 必须!!
Makefile里面就一句
obj-m := hello.o
#make -C /usr/src/linux-source-2.6.15 SUBDIRS=$PWD modules
然后就出现一大堆错误~~
出现的错误太多了 ~~COPY了前面几行和后面几行,太多了显示不下~中没有全部COPY下来,大家帮我看下吧~~谢谢了
/******************************************************************************************/
make: Entering directory `/usr/src/linux-source-2.6.15'
Makefile:490: .config: No such file or directory
WARNING: Symbol version dump /usr/src/linux-source-2.6.15/Module.symvers
is missing; modules will have no dependencies and modversions.
CC [M] /home/wyc/drivers/hello.o
cc1: error: include/linux/autoconf.h: No such file or directory
In file included from include/linux/module.h:9,
from /home/wyc/drivers/hello.c:1:
include/linux/config.h:6:28: error: linux/autoconf.h: No such file or directory
In file included from include/linux/module.h:10,
from /home/wyc/drivers/hello.c:1:
include/linux/sched.h:4:36: error: asm/param.h: No such file or directory
In file included from include/linux/posix_types.h:47,
from include/linux/types.h:14,
from include/linux/capability.h:16,
from include/linux/sched.h:7,
from include/linux/module.h:10,
from /home/wyc/drivers/hello.c:1:
/usr/lib/gcc/i486-linux-gnu/4.0.3/include/asm/posix_types.h:13:22: error: features.h: No such file or directory
/usr/lib/gcc/i486-linux-gnu/4.0.3/include/asm/posix_types.h:14:35: error: no include path in which to search for asm/posix_types.h
In file included from include/linux/capability.h:16,
from include/linux/sched.h:7,
from include/linux/module.h:10,
from /home/wyc/drivers/hello.c:1:
include/linux/types.h:15:23: error: asm/types.h: No such file or directory
In file included from include/linux/capability.h:16,
from include/linux/sched.h:7,
from include/linux/module.h:10,
from /home/wyc/drivers/hello.c:1:
..........................
.........................帖子太长,不让我递交,中间的 只好略过了
........................
include/linux/kobject.h:33: 警告: 数据定义时没有类型或存储类
include/linux/kobject.h:38: 错误: 字段 ‘kref’ 的类型不完全
include/linux/kobject.h:153: 错误: 字段 ‘rwsem’ 的类型不完全
include/linux/kobject.h:236: 错误: 字段 ‘attr’ 的类型不完全
include/linux/kobject.h:237: 错误: syntax error before ‘ssize_t’
include/linux/kobject.h:237: 警告: 结构或联合后没有分号
include/linux/kobject.h:238: 错误: syntax error before ‘*’ token
include/linux/kobject.h:238: 错误: syntax error before ‘size_t’
include/linux/kobject.h:238: 警告: 在 ‘ssize_t’ 的声明中,类型默认为 ‘int’
include/linux/kobject.h:238: 警告: 函数声明不是一个原型
include/linux/kobject.h:238: 错误: ‘ssize_t’ 声明为返回一个函数的函数
include/linux/kobject.h:238: 警告: 函数声明不是一个原型
include/linux/kobject.h:238: 错误: ‘ssize_t’ 被重新声明为不同意义的符号
include/linux/types.h:70: 错误: ‘ssize_t’ 的上一个声明在此
include/linux/kobject.h:238: 警告: 数据定义时没有类型或存储类
In file included from /home/wyc/drivers/hello.c:1:
include/linux/module.h:21:23: error: asm/local.h: No such file or directory
include/linux/module.h:23:24: error: asm/module.h: No such file or directory
In file included from /home/wyc/drivers/hello.c:1:
include/linux/module.h:50: 错误: 字段 ‘attr’ 的类型不完全
include/linux/module.h:51: 错误: syntax error before ‘ssize_t’
include/linux/module.h:51: 警告: 结构或联合后没有分号
include/linux/module.h:52: 错误: syntax error before ‘*’ token
include/linux/module.h:53: 错误: syntax error before ‘size_t’
include/linux/module.h:53: 警告: 在 ‘ssize_t’ 的声明中,类型默认为 ‘int’
include/linux/module.h:53: 警告: 函数声明不是一个原型
include/linux/module.h:53: 错误: ‘ssize_t’ 声明为返回一个函数的函数
include/linux/module.h:53: 警告: 函数声明不是一个原型
include/linux/module.h:53: 错误: ‘ssize_t’ 被重新声明为不同意义的符号
include/linux/types.h:70: 错误: ‘ssize_t’ 的上一个声明在此
include/linux/module.h:53: 警告: 数据定义时没有类型或存储类
include/linux/module.h:57: 错误: syntax error before ‘}’ token
/home/wyc/drivers/hello.c:2:27: error: linux/config.h: No such file or directory
/home/wyc/drivers/hello.c:15: 致命错误: 打开依赖文件 /home/wyc/drivers/.hello.o.d:Permission denied
编译中断。
make[1]: *** [/home/wyc/drivers/hello.o] 错误 1
make: *** [_module_/home/wyc/drivers] 错误 2
make: Leaving directory `/usr/src/linux-source-2.6.15'
/**********************************************************************************************/
不知道是代码错误还是我有什么地方配置错误了,大家帮 我 看看吧
|
我想可能先编译一遍内核会好些
|
内核代码目录树要是编译过的,才会有对应的文件