linux 编译内核 ,请各位大神帮忙看看。两个c文件编译一个内核模块,是不是我的makefile文件写的不对?hello.c和caculate.c

sh123123555 2015-12-24 03:29:03
hello.c文件
1 #include<linux/module.h>
2 #include<linux/init.h>
3
4 extern int add_integar(int a,int b);
5 extern int sub_integar(int a,int b);
6
7 static int __init hello_init(void)
8 {
9 int res = add_integar(1,2);
10 return 0;
11
12 }
13
14 static void __exit hello_exit(void)
15 {
16 int res = sub_integar(2,1);
17 }
18 module_init(hello_init);
19 module_exit(hello_exit);

caculate.c文件
1 #include<linux/init.h>
2 #include<linux/module.h>
3 int add_integar(int a,int b)
4 {
5 return a+b;
6 }
7 int sub_integar(int a,int b)
8 {
9 return a-b;
10
11 }
12 static int __init sym_init()
13 {
14 return 0;
15 }
16 static void __exit sym_exit()
17 {
18
19 }
20 module_init(sym_init);
21 module_exit(sym_exit);
22 //EXPORT_SYMBOL(add_integar);
23 //EXPORT_SYMBOL(sub_integar);

makefile 文件
1 ifneq ($(KERNELRELEASE),)
2 obj-m := hi.o
3 hi-objs := hello.o caculate.o
4 else
5 KDIR := /lib/modules/2.6.18-194.el5/build
6 all:
7 make -C $(KDIR) M=$(PWD) modules
8 clean:
9 rm -f *.ko *.o *.mod.o *.mod.c *.symvers
10 endif
...全文
193 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
sh123123555 2015-12-24
  • 打赏
  • 举报
回复
恩恩,后面搞出来啦。经你点化一下,明白些了。谢谢。
nswcfd 2015-12-24
  • 打赏
  • 举报
回复
楼主的makefile是说生成一个模块hi.ko,它由两个.o组成。 module_init和module_exit只出现在一个.o里面即可。

1,318

社区成员

发帖
与我相关
我的任务
社区描述
主要是开发驱动技术
社区管理员
  • 驱动程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧