+ -
当前位置:首页 → 问答吧 → Linux模块编译问题

Linux模块编译问题

时间:2007-12-04

来源:互联网

想整理下设备驱动这块的知识。
结果用模块编译的时候出现了如下的错误:
源文件:
//mydisk.c
#include   <linux/kernel.h>
#include   <linux/module.h>
#include   <linux/fs.h>
#include   <linux/devfs_fs_kernel.h>
#include   <asm/io.h>
#include   <asm/uaccess.h>
#include   <linux/mm.h>
#include   <linux/errno.h>
#include   <asm/segment.h>
#include   <linux/sched.h>

#include   "mydisk.h"


struct   file_operations   mydisk_fops={
open: generic_file_open,
write: generic_file_write,
release: generic_file_release,
ioctl: generic_file_ioctl,
llseek: generic_file_llseek,
read: generic_file_read,
};

int   init_modules(void)
{
printk(KERN_INFO   "MOUNT   IDE   DISK...\N");
if(register_blkdev(DEV_MAJOR,DEV_NAME,&mydisk_fops) <0)
{
printk(KERN_INFO   "Couldn't   register   a   device.\n");
return   -1;
}

return   0;
}


int   cleanup_modlue(void)
{
if(unregister_blkdev(DEV_MAJOR,DEV_NAME))
printk("Failed   to   unregister   device.\n");

else

printk("Device   uninstalled.\n");

}

MODULE_LICENSE("GPL");

//mydisk.h
#ifndef   _MYDISK_H_

#define   DEV_MAJOR   3

#define   DEV_NAME   "IDEDISK"

#endif

编译:

gcc   -c   mydisk.c   -D_KERNEL_   -DMODULE   -O2   -g   -Wall     -o   mydisk.o

错误提示:
In   file   included   from   /usr/include/linux/sched.h:14
                                  from   /usr/include/linux/mm.h:4
                                  from   /usr/include/linux/locks.h:5
                                  from   /usr/include/linux/devfs_fs_kernel.h:6,
                                  from   mydisk.c:4
/usr/include/linux/timex.h:173:   field   'time'   has   incomplete   type
/usr/include/linux/timex.h:188:   confused   by   earlier   errors,   bailing   out

///////////////////////////////////////
1.这个问题怎么解决?
2.以前没写过Linux的驱动,甚至程序也不怎么写过,想问一下,模块编译时候的头文件包含到底要怎么办,都弄不太清楚。
希望前辈指点。谢谢。。。~~~      

作者: sfezst   发布时间: 2007-12-04

希望大家帮助下那。。。。      

作者: sfezst   发布时间: 2007-12-04