liunx 驱动测试小程序不能编译,求指导
一下是我的一个linux驱动的测试小程序,但是编译时老是报:fatal error: linux/module.h: No such file or directory这样的错误,我用-I指令将其路径加了进去还是不行,以下是源码:我看网上说着要用makefile编译,我是菜鸟写了一个不好使,忘大神能指导一下
#define __NO_VERSION__
#include <linux/version.h>
#include <linux/module.h>
char kernel_version [] = UTS_RELEASE;
#include <linux/types.h> #include <linux/fs.h> #include <linux/mm.h> #include <linux/errno.h> #include <asm/segment.h> unsigned int test_major = 0;
static int read_test(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--)
{
__put_user(1,buf,1); buf++;
}
return count;
}
static int write_test(struct inode *inode,struct file *file,const char *buf,int count)
{
return count;
}
static int open_tibet(struct inode *inode,struct file *file )
{
MOD_INC_USE_COUNT;
return 0;
}
static void release_test(struct inode *inode,struct file *file )
{
MOD_DEC_USE_COUNT;
}
struct file_operations test_fops =
{
NULL,
read_test,
write_test,
NULL, /* test_readdir */
NULL,
NULL, /* test_ioctl */
NULL, /* test_mmap */
open_test,
release_test,
NULL, /* test_fsync */
NULL, /* test_fasync */
/* nothing more, fill with NULLs */
};
int init_module(void)
{
int result;
result = register_chrdev(0, "test", &test_fops);
if (result < 0)
{
printk(KERN_INFO "test: can't get major number\n");
return result;
}
if (test_major == 0)
test_major = result; /* dynamic */
return 0;
}
void cleanup_module(void)
{
unregister_chrdev(test_major,"test");
}
------解决方案--------------------
可能你的Makefile有问题
Assembly code
obj-m := test.o
KDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
EXTRA_CFLAGS += -O2 -Wall
all: module cleanup
module:
$(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
cleanup:
rm -f *.o .*.cmd *.mod.c; rm -rf .tmp_versions
clean: cleanup
rm -f *.ko test
------解决方案--------------------
当然了,还需要上面仁兄提供的 makefile没问题。