make -f 编译不成功

发布时间 2023-12-10 01:11:41作者: HelliWrold1

make -f 编译不成功

编译内核模块时使用自己make -f 指定的xxMakefilexx编译的目标不正确或编译失败

在学习编译驱动模块时,使用了自己的myMakefile,发现编译的目标还是原来的Makefile指定的目标

前提: 根据教程编写了自己的驱动源码以及Makefile

预期效果:编译得到my_hello_driv.ko、my_hello_driv.o、hello_drv_test.o

hello_drv.c  hello_drv_test.c  Makefile  Makefile.bak  my_hello_driv.c  myMakfile

但是得到的结果是

hello_drv.c   hello_drv.mod.c  hello_drv.o     hello_drv_test.c  Makefile.bak   Module.symvers   myMakfile
hello_drv.ko  hello_drv.mod.o  hello_drv_test  Makefile          modules.order  my_hello_driv.c

发现其编译的还是hello_drv.c

后来删除掉默认的Makfile再make -f myMakefile编译,发现编译内核模块时,会进入内核目录,内核目录的/scripts/Makefile.build文件,会返回到你编译内核模块的目录查找默认的Makefile文件,即使指定了Makefile文件,仍然编译的是别的文件(默认Makefile存在且有效时),或者编译失败提示

make[1]: Entering directory '/home/book/100ask_imx6ull-sdk/Linux-4.9.88'
scripts/Makefile.build:44: /mnt/hgfs/vmfileshare/01_all_series_quickstart/05_嵌入式Linux驱动开发基础知识/source/01_hello_drv/Makefile: No such file or directory