gigimao
驱动牛犊
驱动牛犊
  • 注册日期2003-03-23
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
阅读:1209回复:3

内核编程时怎么处理版本问题?(给20分)

楼主#
更多 发布于:2003-05-09 17:13
我在进行内核编程时,连最简单的hello.c程序都出现错误:
/* gcc -c hello.c
* insmod hello.o
* rmmod hello.o
*/

#define MODULE
#include <linux/module.h>

void init_module(void)
{
    printk(\"hello,world\\n\");
    return 0;
}

void cleanup_module(void)
{
    printk(\"goodbye cruel world\\n\");
}


编译后,出现以下错误:
[root@gigimao test]# gcc -c hello.c

In file included from hello.c:7:
/usr/include/linux/module.h:60: parse error before `atomic_t\'
/usr/include/linux/module.h:60: warning: no semicolon at end of struct or union
/usr/include/linux/module.h:60: warning: no semicolon at end of struct or union
/usr/include/linux/module.h:62: parse error before `}\'
/usr/include/linux/module.h:62: warning: data definition has no type or storage class
/usr/include/linux/module.h:91: parse error before `}\'
noname1.c: In function `init_module\':
noname1.c:12: warning: `return\' with a value, in function returning void

请高手看看,这是什么问题?

 :(
chensuoqian
驱动牛犊
驱动牛犊
  • 注册日期2003-02-25
  • 最后登录2003-06-04
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
沙发#
发布于:2003-05-09 21:24
你用的是哪个版本的linux?如果是redhat8。0的话,用如下命令即可,如果用的是其他版本,只要修改内核文件的路径即可。
gcc -D__KERNEL__ -D__SMP__ -DMODULE -DEXPORT_SYMTAB -c -I/usr/src/linux-2.4.18-14/include -o filename.o
filename.c
zheng2002
驱动中牛
驱动中牛
  • 注册日期2002-04-17
  • 最后登录2004-12-13
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
板凳#
发布于:2003-05-10 21:53
一般只要该这个目录 -I/usr/src/linux-2.4.18-14/include
不同内核的话,模块中加以判断
qq:14459938 email:zheng2002@21cn.com RH9 kernel 2.4.20
gigimao
驱动牛犊
驱动牛犊
  • 注册日期2003-03-23
  • 最后登录2016-01-09
  • 粉丝0
  • 关注0
  • 积分0分
  • 威望0点
  • 贡献值0点
  • 好评度0点
  • 原创分0分
  • 专家分0分
地板#
发布于:2003-05-10 23:21
非常感谢楼上的各位,问题已经解决了。 :)
游客

返回顶部