|
我在编译下面的程序时,出错说找不到modules.h
好像是没有这个文件,它在那儿呢?》??
----------------codes-------------------------
/*
*来源,《嵌入式LINUX应用开发详解》,204页
*/
#define _NO_VERSION_
#include <linux/modules.h>
#include <linux/version.h>
char kerneal_version[]=UTS_RELEASE;
#define KERNAL
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/mm.h>
#include <linux/errno.h>
#include <asm/segment.h>
#define SUCCESS 0
static int device_read(struct inode*, struct file*, char*, int);
static int device_open(struct inode*, struct file*);
static int device_release(struct inode*, struct file*);
/*in fs.h defined data struct about entry*/
struct file_operations tdd_fops=
{
NULL,
device_read,
NULL,
NULL,
NULL,
NULL,
NULL,
device_open,
device_release,
NULL,
NULL,
NULL,
NULL
};
/*indefine devices that will show in /proc/devices */
#define DEVICE_NAME "char_dev"
/*prevent onthers access the device at the same time */
static int Device_open = 0;
unsigned int test_major= 0;
/*when the device is queryed, get out messages */
static char Message[BUF_LEN];
/*this function will be call, when someone try open device*/
static int device_open(struct inode *inode, struct file *file){
#ifdef DEBUG
printk("device_open(%p)\n",file);
#endif
/*don't talk with two process, at the same time*/
if(Device_Open)
return -EBUSY;
Device_Open++;
MOD_INC_USE_COUNT;
return SUCCESS;
}
/*this function will be call, when to close device*/
static void device_release(struct inode *inode, struct file *file)
{
#ifdef DEBUG
printk("device_release(%p,%p)\n", inode,file);
#endif
/*ready to next call*/
Device_Open--;
MOD_DEC_USE_COUNT;
}
/*read() entry, that ready for calling read()
when call read(), read_test() will be call, and write '1' to all buffer
*/
static int device_read(struct inode *node, struct file *file, char *buf, int count)
{
int left;
if(verify_area(VERIFY_WRITE,buf,count)==-EFAULT)
return -EFAULT;
for(left=count; left>0; left--)
{
/*when device_read() is called, system enter sys-static. so, you cann't use 'buf' address, and must use _put_user() that kernel privded using to transalt data. and others refere to <linux/mm.h>*/
_put_user(1,buf,1);
buf++;
}
return count;
}
/*init_module register device to char_dev table*/
int init_module(void)
{
int result;
/*register char device*/
result=register_chrdev(0,"char_dev",&tdd_fops);
if(result<0)
{
printk(KERN_INFO "char_dev: can't get major number\n");
return result;
}
/*if register successed, return 0, and get device major number, else return nagtive value*/
if(test_major==0) test_major=result;
/*install it to kernal, print notes*/
printk("Hello, I'm in kernel mode\n");
return 0;
}
void cleanup_module(void)
{
printk("Hello, I'm going to out\n");
unregister_chrdev(test_major, "test");
}
-------------------------------compiled----------------------
gcc -O2 -DMODULE -D_KERNAL_ -c TestDriver.c
-------------------------------error----------------------------
[root@localhost linux-program]# ./build-TestDriver
TestDriver.c:5:27: linux/modules.h: 没有那个文件或目录
In file included from /usr/include/linux/sched.h:14,
from /usr/include/linux/mm.h:4,
from TestDriver.c:11:
/usr/include/linux/timex.h:173: field `time' has incomplete type
In file included from /usr/include/linux/bitops.h:69,
from /usr/include/asm/system.h:7,
from /usr/include/linux/sched.h:16,
from /usr/include/linux/mm.h:4,
from TestDriver.c:11:
/usr/include/asm/bitops.h:327:2: warning: #warning This includefile is not available on all architectures.
/usr/include/asm/bitops.h:328:2: warning: #warning Using kernel headers in userspace: atomicity not guaranteed
In file included from /usr/include/linux/signal.h:4,
from /usr/include/linux/sched.h:25,
from /usr/include/linux/mm.h:4,
from TestDriver.c:11:
/usr/include/asm/signal.h:107: parse error before "sigset_t"
/usr/include/asm/signal.h:110: parse error before '}' token
In file included from /usr/include/linux/sched.h:81,
from /usr/include/linux/mm.h:4,
from TestDriver.c:11:
/usr/include/linux/timer.h:32: field `vec' has incomplete type
/usr/include/linux/timer.h:37: field `vec' has incomplete type
/usr/include/linux/timer.h:45: parse error before "spinlock_t"
/usr/include/linux/timer.h:53: parse error before '}' token
/usr/include/linux/timer.h:63: field `list' has incomplete type
/usr/include/linux/timer.h:67: parse error before "tvec_base_t"
/usr/include/linux/timer.h:101: parse error before "tvec_bases"
/usr/include/linux/timer.h: In function `init_timer':
/usr/include/linux/timer.h:105: dereferencing pointer to incomplete type
/usr/include/linux/timer.h:105: dereferencing pointer to incomplete type
/usr/include/linux/timer.h:106: dereferencing pointer to incomplete type
/usr/include/linux/timer.h: In function `timer_pending':
/usr/include/linux/timer.h:121: dereferencing pointer to incomplete type
TestDriver.c: At top level:
TestDriver.c:15: warning: `struct file' declared inside parameter list
TestDriver.c:15: warning: its scope is only this definition or declaration, which is probably not what you want
TestDriver.c:15: warning: `struct inode' declared inside parameter list
TestDriver.c:16: warning: `struct file' declared inside parameter list
TestDriver.c:16: warning: `struct inode' declared inside parameter list
TestDriver.c:17: warning: `struct file' declared inside parameter list
TestDriver.c:17: warning: `struct inode' declared inside parameter list
TestDriver.c:19: variable `tdd_fops' has initializer but incomplete type
TestDriver.c:21: warning: excess elements in struct initializer
TestDriver.c:21: warning: (near initialization for `tdd_fops')
TestDriver.c:22: warning: excess elements in struct initializer
TestDriver.c:22: warning: (near initialization for `tdd_fops')
TestDriver.c:23: warning: excess elements in struct initializer
TestDriver.c:23: warning: (near initialization for `tdd_fops')
TestDriver.c:24: warning: excess elements in struct initializer
TestDriver.c:24: warning: (near initialization for `tdd_fops')
TestDriver.c:25: warning: excess elements in struct initializer
TestDriver.c:25: warning: (near initialization for `tdd_fops')
TestDriver.c:26: warning: excess elements in struct initializer
TestDriver.c:26: warning: (near initialization for `tdd_fops')
TestDriver.c:27: warning: excess elements in struct initializer
TestDriver.c:27: warning: (near initialization for `tdd_fops')
TestDriver.c:28: warning: excess elements in struct initializer
TestDriver.c:28: warning: (near initialization for `tdd_fops')
TestDriver.c:29: warning: excess elements in struct initializer
TestDriver.c:29: warning: (near initialization for `tdd_fops')
TestDriver.c:30: warning: excess elements in struct initializer
TestDriver.c:30: warning: (near initialization for `tdd_fops')
TestDriver.c:31: warning: excess elements in struct initializer
TestDriver.c:31: warning: (near initialization for `tdd_fops')
TestDriver.c:32: warning: excess elements in struct initializer
TestDriver.c:32: warning: (near initialization for `tdd_fops')
TestDriver.c:34: warning: excess elements in struct initializer
TestDriver.c:34: warning: (near initialization for `tdd_fops')
TestDriver.c:41: `BUF_LEN' undeclared here (not in a function)
TestDriver.c:43: warning: `struct file' declared inside parameter list
TestDriver.c:43: warning: `struct inode' declared inside parameter list
TestDriver.c:43: conflicting types for `device_open'
TestDriver.c:16: previous declaration of `device_open'
TestDriver.c: In function `device_open':
TestDriver.c:49: `Device_Open' undeclared (first use in this function)
TestDriver.c:49: (Each undeclared identifier is reported only once
TestDriver.c:49: for each function it appears in.)
TestDriver.c:53: `MOD_INC_USE_COUNT' undeclared (first use in this function)
TestDriver.c: At top level:
TestDriver.c:58: warning: `struct file' declared inside parameter list
TestDriver.c:58: warning: `struct inode' declared inside parameter list
TestDriver.c:59: conflicting types for `device_release'
TestDriver.c:17: previous declaration of `device_release'
TestDriver.c: In function `device_release':
TestDriver.c:65: `Device_Open' undeclared (first use in this function)
TestDriver.c:66: `MOD_DEC_USE_COUNT' undeclared (first use in this function)
TestDriver.c: At top level:
TestDriver.c:72: warning: `struct file' declared inside parameter list
TestDriver.c:72: warning: `struct inode' declared inside parameter list
TestDriver.c:73: conflicting types for `device_read'
TestDriver.c:15: previous declaration of `device_read'
TestDriver.c: In function `device_read':
TestDriver.c:75: `VERIFY_WRITE' undeclared (first use in this function)
TestDriver.c: In function `init_module':
TestDriver.c:94: `KERN_INFO' undeclared (first use in this function)
TestDriver.c:94: parse error before string constant
/usr/include/asm/processor.h: At top level:
TestDriver.c:19: storage size of `tdd_fops' isn't known
TestDriver.c:41: storage size of `Message' isn't known
=======================================================
高手指点,我是用的书上的例子,,对驱动开发不懂哈 |
|