免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2333 | 回复: 1
打印 上一主题 下一主题

makefile怎么写 module不能加载 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-06-10 15:03 |只看该作者 |倒序浏览
test1.c:

#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>

#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!
加载时就抱怨说有不识别的标志,加不上。

大家帮我看一下,这个要怎么改

谢谢!

论坛徽章:
0
2 [报告]
发表于 2008-06-10 22:15 |只看该作者
樓主的文件目錄是怎麼放置的呀
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP