#include
#include
#include
#include "xiao.h"
MODULE_DESCRIPTION("My kernel module");
MODULE_AUTHOR("root (root@localhost.localdomain)");
MODULE_LICENSE("$LICENSE$");
static int test1_init_module(void)
{
int a=3,b=5;
int res;
printk( KERN_DEBUG "Module test1 init\n" );
res=xiao(a,b);
printk( KERN_DEBUG "Module test1 init res=%d \n", res);
return 0;
}
static void test1_exit_module(void)
{
printk( KERN_DEBUG "Module test1 exit\n" );
}
module_init(test1_init_module);
module_exit(test1_exit_module);
****************
xiao.c:
int xiao(int a,int b)
{
int c=a+b;
return(c);
}
***************
#ifndef _XIAO_H_
#define _XIAO_H_
int xiao(int a,int b);
#endif
**********
makefile:
TARGET = test1
OBJS = test1.o xiao.o
MDIR = drivers/misc
EXTRA_CFLAGS = -DEXPORT_SYMTAB
CURRENT = $(shell uname -r)
KDIR = /lib/modules/$(CURRENT)/build
PWD = $(shell pwd)
DEST = /lib/modules/$(CURRENT)/kernel/$(MDIR)
#obj-m := $(TARGET).o
$(TARGET).o-objs:=test1.o xiao.o
obj-m = $(TARGET).o
default:
make -C $(KDIR) SUBDIRS=$(PWD) modules
$(TARGET).o: $(OBJS)
$(LD) $(LD_RFLAG) -r -o $@ $(OBJS)
ifneq (,$(findstring 2.4.,$(CURRENT)))
install:
su -c "cp -v $(TARGET).o $(DEST) && /sbin/depmod -a"
else
install:
su -c "cp -v $(TARGET).ko $(DEST) && /sbin/depmod -a"
endif
clean:
-rm -f *.o *.ko .*.cmd .*.flags *.mod.c
-include $(KDIR)/Rules.make
**************
编译时有警告:WARNING: "xiao" [/root/test1/test1.ko] undefined!
加载时就抱怨说有不识别的标志,加不上。
大家帮我看一下,这个要怎么改
谢谢!