Linux 编译内核模块的通用Makefile

【版权申明】未经博主同意,谢绝转载!(请尊重原创,博主保留追究权) 

Linux 编译内核模块的通用Makefile

KERN_DIR := xxxxx/linux-4.9.y-smp

all:
	make -C $(KERN_DIR) M=`pwd` modules

clean:
	make -C $(KERN_DIR) M=`pwd` modules clean
	rm -rf modules.order

obj-m += led_drv.o

KERN_DIR 指向Linux内核路径;
obj-m 后面加的是驱动文件的对象文件(你应该懂的)

你有可能出现的问题, 当然问题不在Makefile上:

..... 上面的忽略, 毕竟太长了 .....
..... 上面的忽略, 毕竟太长了 .....
..... 上面的忽略, 毕竟太长了 .....

./include/linux/thread_info.h:108:22: error: implicit declaration of function ‘current_thread_info’; did you mean ‘current_text_addr’? [-Werror=implicit-function-declaration]
  test_ti_thread_flag(current_thread_info(), flag)
                      ^
./arch/x86/include/asm/elf.h:349:3: note: in expansion of macro ‘test_thread_flag’
   test_thread_flag(TIF_ADDR32));
   ^~~~~~~~~~~~~~~~
./include/linux/thread_info.h:108:22: warning: passing argument 1 of ‘test_ti_thread_flag’ makes pointer from integer without a cast [-Wint-conversion]
  test_ti_thread_flag(current_thread_info(), flag)
                      ^
./arch/x86/include/asm/elf.h:349:3: note: in expansion of macro ‘test_thread_flag’
   test_thread_flag(TIF_ADDR32));
   ^~~~~~~~~~~~~~~~
./include/linux/thread_info.h:94:19: note: expected ‘struct thread_info *’ but argument is of type ‘intstatic inline int test_ti_thread_flag(struct thread_info *ti, int flag)
                   ^~~~~~~~~~~~~~~~~~~
In file included from ./include/linux/module.h:25:0,
                 from xxxxx/led_cntl/led_drv.c:2:
./arch/x86/include/asm/module.h: At top level:
./arch/x86/include/asm/module.h:57:2: error: #error unknown processor family
 #error unknown processor family
  ^~~~~
In file included from xxxxx/led_cntl/led_drv.c:2:0:
./include/linux/module.h:400:27: error: field ‘arch’ has incomplete type
  struct mod_arch_specific arch;
                           ^~~~
cc1: some warnings being treated as errors
scripts/Makefile.build:299: recipe for target 'xxxxx/led_cntl/led_drv.o' failed
make[2]: *** [xxxxx/led_cntl/led_drv.o] Error 1
Makefile:1490: recipe for target '_module_xxxxx/led_cntl' failed
make[1]: *** [_module_xxxxx/led_cntl] Error 2
make[1]: Leaving directory 'xxxxx/osdrv/opensource/kernel/linux-4.9.y-smp'
Makefile:4: recipe for target 'all' failed
make: *** [all] Error 2

为什么会这样的?
  答: 是因为我们没有指定make时使用的架构和编译链. 我们需要在Makefile中补上.

当我编译内核时, 我使用的是如下的命令:

make ARCH=arm CROSS_COMPILE=arm-himix200-linux- uImage

而我的Makefile中却没有加上ARCH和CROSS_COMPILE参数, 故把Makefile改成如下即可:

KERN_DIR := xxxxx/linux-4.9.y-smp

all:
	make ARCH=arm CROSS_COMPILE=arm-himix200-linux- -C $(KERN_DIR) M=`pwd` modules

clean:
	make ARCH=arm CROSS_COMPILE=arm-himix200-linux- -C $(KERN_DIR) M=`pwd` modules clean
	rm -rf modules.order

obj-m += led_drv.o
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

安河桥

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值