当前位置: 技术问答>linux和unix
刚开始学习linux下的驱动开发,书上的例子编译不了,大家帮忙看看
来源: 互联网 发布时间:2016-04-19
本文导语: 这是《linux程序设计》第三版 18章的第一个例子 源码是这个: /* * Hello world module. */ #include #if defined(CONFIG_SMP) #define __SMP__ #endif #if defined(CONFIG_MODVERSIONS) #define MODVERSIONS #include #endif #include int init_module(void) { ...
这是《linux程序设计》第三版 18章的第一个例子
源码是这个:
/*
* Hello world module.
*/
#include
#if defined(CONFIG_SMP)
#define __SMP__
#endif
#if defined(CONFIG_MODVERSIONS)
#define MODVERSIONS
#include
#endif
#include
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/src/linux/include -DMODULE -Wall -O2 -c hello.c -o hello.o
我的系统是openSUSE 11.0 一开始好像系统没有安装源码,提示一些头文件找不到
后来我从光盘中把源码装入,又有了如下的错误,
我在网上找了一下,好像有同样的问题,不过好像没有被解决,
大家帮帮忙,看看应该如何解决,
这么多错误提示,我一点头绪都没有!!!
错误提示:
$ gcc -D__KERNEL__ -I/usr/src/linux/include -DMODULE -Wall -O2 -c hello.c -o hello.o
In file included from /usr/src/linux/include/linux/prefetch.h:13,
from /usr/src/linux/include/linux/list.h:8,
from /usr/src/linux/include/linux/module.h:9,
from hello.c:4:
/usr/src/linux/include/linux/types.h:197: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘resource_size_t’
In file included from /usr/src/linux/include/linux/list.h:8,
from /usr/src/linux/include/linux/module.h:9,
from hello.c:4:
/usr/src/linux/include/linux/prefetch.h:14:27: error: asm/processor.h: No such file or directory
/usr/src/linux/include/linux/prefetch.h:15:23: error: asm/cache.h: No such file or directory
In file included from /usr/src/linux/include/linux/module.h:9,
from hello.c:4:
/usr/src/linux/include/linux/list.h:9:24: error: asm/system.h: No such file or directory
In file included from /usr/src/linux/include/linux/module.h:9,
from hello.c:4:
/usr/src/linux/include/linux/list.h: In function ‘__list_add_rcu’:
/usr/src/linux/include/linux/list.h:100: warning: implicit declaration of function ‘smp_wmb’
In file included from /usr/src/linux/include/linux/kernel.h:11,
from /usr/src/linux/include/linux/cache.h:4,
from /usr/src/linux/include/linux/time.h:7,
from /usr/src/linux/include/linux/stat.h:60,
from /usr/src/linux/include/linux/module.h:10,
from hello.c:4:
/usr/src/linux/include/linux/linkage.h:4:25: error: asm/linkage.h: No such file or directory
In file included from /usr/src/linux/include/linux/kernel.h:15,
from /usr/src/linux/include/linux/cache.h:4,
from /usr/src/linux/include/linux/time.h:7,
from /usr/src/linux/include/linux/stat.h:60,
from /usr/src/linux/include/linux/module.h:10,
from hello.c:4:
/usr/src/linux/include/linux/bitops.h:17:24: error: asm/bitops.h: No such file or directory
In file included from /usr/src/linux/include/linux/kernel.h:15,
from /usr/src/linux/include/linux/cache.h:4,
from /usr/src/linux/include/linux/time.h:7,
from /usr/src/linux/include/linux/stat.h:60,
from /usr/src/linux/include/linux/module.h:10,
from hello.c:4:
/usr/src/linux/include/linux/bitops.h: In function ‘get_bitmask_order’:
/usr/src/linux/include/linux/bitops.h:29: warning: implicit declaration of function ‘fls’
/usr/src/linux/include/linux/bitops.h: In function ‘hweight_long’:
/usr/src/linux/include/linux/bitops.h:45: warning: implicit declaration of function ‘hweight32’
/usr/src/linux/include/linux/bitops.h:45: warning: implicit declaration of function ‘hweight64’
/usr/src/linux/include/linux/bitops.h: In function ‘fls_long’:
/usr/src/linux/include/linux/bitops.h:112: warning: implicit declaration of function ‘fls64’
In file included from /usr/src/linux/include/linux/kernel.h:16,
from /usr/src/linux/include/linux/cache.h:4,
from /usr/src/linux/include/linux/time.h:7,
from /usr/src/linux/include/linux/stat.h:60,
from /usr/src/linux/include/linux/module.h:10,
from hello.c:4:
/usr/src/linux/include/linux/log2.h: At top level:
/usr/src/linux/include/linux/log2.h:32: error: expected ‘)’ before ‘n’
/usr/src/linux/include/linux/log2.h:40: error: expected ‘)’ before ‘n’
In file included from /usr/src/linux/include/linux/byteorder/little_endian.h:104,
from /usr/include/asm/byteorder.h:69,
from /usr/src/linux/include/linux/kernel.h:17,
from /usr/src/linux/include/linux/cache.h:4,
from /usr/src/linux/include/linux/time.h:7,
from /usr/src/linux/include/linux/stat.h:60,
from /usr/src/linux/include/linux/module.h:10,
from hello.c:4:
/usr/src/linux/include/linux/byteorder/generic.h:149: error: expected declaration specifiers or ‘...’ before ‘u16’
/usr/src/linux/include/linux/byteorder/generic.h: In function ‘le16_add_cpu’:
/usr/src/linux/include/linux/byteorder/generic.h:151: error: ‘val’ undeclared (first use in this function)
/usr/src/linux/include/linux/byteorder/generic.h:151: error: (Each undeclared identifier is reported only once
/usr/src/linux/include/linux/byteorder/generic.h:151: error: for each function it appears in.)
/usr/src/linux/include/linux/byteorder/generic.h: At top level:
/usr/src/linux/include/linux/byteorder/generic.h:154: error: expected declaration specifiers or ‘...’ before ‘u32’
/usr/src/linux/include/linux/byteorder/generic.h: In function ‘le32_add_cpu’:
/usr/src/linux/include/linux/byteorder/generic.h:156: error: ‘val’ undeclared (first use in this function)
/usr/src/linux/include/linux/byteorder/generic.h: At top level:
/usr/src/linux/include/linux/byteorder/generic.h:159: error: expected declaration specifiers or ‘...’ before ‘u64’
/usr/src/linux/include/linux/byteorder/generic.h: In function ‘le64_add_cpu’:
错误提示还有很多!!
这儿好像不能发这么长的问题!!
我在CU上也发了这个问题 大家看看把!!
http://linux.chinaunix.net/bbs/viewthread.php?tid=1037373&extra=page%3D1
源码是这个:
/*
* Hello world module.
*/
#include
#if defined(CONFIG_SMP)
#define __SMP__
#endif
#if defined(CONFIG_MODVERSIONS)
#define MODVERSIONS
#include
#endif
#include
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/src/linux/include -DMODULE -Wall -O2 -c hello.c -o hello.o
我的系统是openSUSE 11.0 一开始好像系统没有安装源码,提示一些头文件找不到
后来我从光盘中把源码装入,又有了如下的错误,
我在网上找了一下,好像有同样的问题,不过好像没有被解决,
大家帮帮忙,看看应该如何解决,
这么多错误提示,我一点头绪都没有!!!
错误提示:
$ gcc -D__KERNEL__ -I/usr/src/linux/include -DMODULE -Wall -O2 -c hello.c -o hello.o
In file included from /usr/src/linux/include/linux/prefetch.h:13,
from /usr/src/linux/include/linux/list.h:8,
from /usr/src/linux/include/linux/module.h:9,
from hello.c:4:
/usr/src/linux/include/linux/types.h:197: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘resource_size_t’
In file included from /usr/src/linux/include/linux/list.h:8,
from /usr/src/linux/include/linux/module.h:9,
from hello.c:4:
/usr/src/linux/include/linux/prefetch.h:14:27: error: asm/processor.h: No such file or directory
/usr/src/linux/include/linux/prefetch.h:15:23: error: asm/cache.h: No such file or directory
In file included from /usr/src/linux/include/linux/module.h:9,
from hello.c:4:
/usr/src/linux/include/linux/list.h:9:24: error: asm/system.h: No such file or directory
In file included from /usr/src/linux/include/linux/module.h:9,
from hello.c:4:
/usr/src/linux/include/linux/list.h: In function ‘__list_add_rcu’:
/usr/src/linux/include/linux/list.h:100: warning: implicit declaration of function ‘smp_wmb’
In file included from /usr/src/linux/include/linux/kernel.h:11,
from /usr/src/linux/include/linux/cache.h:4,
from /usr/src/linux/include/linux/time.h:7,
from /usr/src/linux/include/linux/stat.h:60,
from /usr/src/linux/include/linux/module.h:10,
from hello.c:4:
/usr/src/linux/include/linux/linkage.h:4:25: error: asm/linkage.h: No such file or directory
In file included from /usr/src/linux/include/linux/kernel.h:15,
from /usr/src/linux/include/linux/cache.h:4,
from /usr/src/linux/include/linux/time.h:7,
from /usr/src/linux/include/linux/stat.h:60,
from /usr/src/linux/include/linux/module.h:10,
from hello.c:4:
/usr/src/linux/include/linux/bitops.h:17:24: error: asm/bitops.h: No such file or directory
In file included from /usr/src/linux/include/linux/kernel.h:15,
from /usr/src/linux/include/linux/cache.h:4,
from /usr/src/linux/include/linux/time.h:7,
from /usr/src/linux/include/linux/stat.h:60,
from /usr/src/linux/include/linux/module.h:10,
from hello.c:4:
/usr/src/linux/include/linux/bitops.h: In function ‘get_bitmask_order’:
/usr/src/linux/include/linux/bitops.h:29: warning: implicit declaration of function ‘fls’
/usr/src/linux/include/linux/bitops.h: In function ‘hweight_long’:
/usr/src/linux/include/linux/bitops.h:45: warning: implicit declaration of function ‘hweight32’
/usr/src/linux/include/linux/bitops.h:45: warning: implicit declaration of function ‘hweight64’
/usr/src/linux/include/linux/bitops.h: In function ‘fls_long’:
/usr/src/linux/include/linux/bitops.h:112: warning: implicit declaration of function ‘fls64’
In file included from /usr/src/linux/include/linux/kernel.h:16,
from /usr/src/linux/include/linux/cache.h:4,
from /usr/src/linux/include/linux/time.h:7,
from /usr/src/linux/include/linux/stat.h:60,
from /usr/src/linux/include/linux/module.h:10,
from hello.c:4:
/usr/src/linux/include/linux/log2.h: At top level:
/usr/src/linux/include/linux/log2.h:32: error: expected ‘)’ before ‘n’
/usr/src/linux/include/linux/log2.h:40: error: expected ‘)’ before ‘n’
In file included from /usr/src/linux/include/linux/byteorder/little_endian.h:104,
from /usr/include/asm/byteorder.h:69,
from /usr/src/linux/include/linux/kernel.h:17,
from /usr/src/linux/include/linux/cache.h:4,
from /usr/src/linux/include/linux/time.h:7,
from /usr/src/linux/include/linux/stat.h:60,
from /usr/src/linux/include/linux/module.h:10,
from hello.c:4:
/usr/src/linux/include/linux/byteorder/generic.h:149: error: expected declaration specifiers or ‘...’ before ‘u16’
/usr/src/linux/include/linux/byteorder/generic.h: In function ‘le16_add_cpu’:
/usr/src/linux/include/linux/byteorder/generic.h:151: error: ‘val’ undeclared (first use in this function)
/usr/src/linux/include/linux/byteorder/generic.h:151: error: (Each undeclared identifier is reported only once
/usr/src/linux/include/linux/byteorder/generic.h:151: error: for each function it appears in.)
/usr/src/linux/include/linux/byteorder/generic.h: At top level:
/usr/src/linux/include/linux/byteorder/generic.h:154: error: expected declaration specifiers or ‘...’ before ‘u32’
/usr/src/linux/include/linux/byteorder/generic.h: In function ‘le32_add_cpu’:
/usr/src/linux/include/linux/byteorder/generic.h:156: error: ‘val’ undeclared (first use in this function)
/usr/src/linux/include/linux/byteorder/generic.h: At top level:
/usr/src/linux/include/linux/byteorder/generic.h:159: error: expected declaration specifiers or ‘...’ before ‘u64’
/usr/src/linux/include/linux/byteorder/generic.h: In function ‘le64_add_cpu’:
错误提示还有很多!!
这儿好像不能发这么长的问题!!
我在CU上也发了这个问题 大家看看把!!
http://linux.chinaunix.net/bbs/viewthread.php?tid=1037373&extra=page%3D1
|
你先检查一下
1) 你所模块代码的写法跟你机子上内核版本相一致吗?
2) 编译模块之前先编译了内核了吗?
2.6.x的模块代码里都调用了 module_init 和module_exit。这是它标准的写法。
你可以参考Linux Device Drive 3rd 的 2.2. The Hello World Module
和2.4. Compiling and Loading
1) 你所模块代码的写法跟你机子上内核版本相一致吗?
2) 编译模块之前先编译了内核了吗?
2.6.x的模块代码里都调用了 module_init 和module_exit。这是它标准的写法。
你可以参考Linux Device Drive 3rd 的 2.2. The Hello World Module
和2.4. Compiling and Loading