編譯核心模組常見問題
阿新 • • 發佈:2018-11-10
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow
也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!
在x86上做出來了,但是在ARM上卻出現了很多問題,有核心程式碼準備的問題,有模組程式碼問題,也有Makefile的問題。看似不起眼的角色,出了問題也很糾結。
第一種:核心程式碼沒有準備好
[[email protected] module]# make make -C /opt/kangear/kernel/linux-2.6.32.2 M=/root/桌面/kangear/module modulesmake[1]: Entering directory `/opt/kangear/kernel/linux-2.6.32.2' ERROR: Kernel configuration is invalid. include/linux/autoconf.h or include/config/auto.conf are missing. Run 'make oldconfig && make prepare' on kernel src to fix it. WARNING: Symbol version dump /opt/kangear/kernel/linux-2.6.32.2/Module.symvers is missing; modules will have no dependencies and modversions. Building modules, stage 2./opt/kangear/kernel/linux-2.6.32.2/scripts/Makefile.modpost:42: include/config/auto.conf: 沒有那個檔案或目錄make[2]: *** 沒有規則可以建立目標“include/config/auto.conf”。 停止。make[1]: *** [modules] 錯誤 2make[1]: Leaving directory `/opt/kangear/kernel/linux-2.6.32.2'make: *** [all] 錯誤 2[ [email protected] module]#
這種是下載的很乾淨的核心,配置都沒有配置;或是配置了,有.config但是沒有make zImage。編譯一下,不為用這個zImage,只是為了更好的編譯核心模組。
其實看實質就是找不到auto.conf,這個其實已經有了,就是.config,但是如果不想手動來拷貝可以假裝make zImage(如下),這裡就可以了,完整的編譯一個核心只為了這個一個配置檔案,也太浪費了。
[[email protected] linux-2.6.32.2]# make zImage HOSTLD scripts/kconfig/confscripts/kconfig/conf -s arch/arm/Kconfig CHK include/linux/version.h UPD include/linux/version.h Generating include/asm-arm/mach-types.h CHK include/linux/utsrelease.h UPD include/linux/utsrelease.h SYMLINK include/asm -> include/asm-arm CC kernel/bounds.s GEN include/linux/bounds.h CC arch/arm/kernel/asm-offsets.s GEN include/asm/asm-offsets.h CALL scripts/checksyscalls.sh CC scripts/mod/empty.o HOSTCC scripts/mod/mk_elfconfig MKELF scripts/mod/elfconfig.h HOSTCC scripts/mod/file2alias.o HOSTCC scripts/mod/modpost.o HOSTCC scripts/mod/sumversion.o HOSTLD scripts/mod/modpost HOSTCC scripts/kallsyms HOSTCC scripts/pnmtologo HOSTCC scripts/conmakehash CC init/main.o CHK include/linux/compile.h UPD include/linux/compile.h CC init/version.o^Cmake[1]: *** wait: 沒有子程序。 停止。make[1]: *** 正在等待未完成的任務....make[1]: *** wait: 沒有子程序。 停止。make: *** wait: 沒有子程序。 停止。make: *** 正在等待未完成的任務....make: *** wait: 沒有子程序。 停止。[[email protected] linux-2.6.32.2]#
這裡再來make一下:
[[email protected] module]# makemake -C /opt/kangear/kernel/linux-2.6.32.2 M=/root/桌面/kangear/module modulesmake[1]: Entering directory `/opt/kangear/kernel/linux-2.6.32.2' WARNING: Symbol version dump /opt/kangear/kernel/linux-2.6.32.2/Module.symvers is missing; modules will have no dependencies and modversions. CC [M] /root/桌面/kangear/module/hello.o Building modules, stage 2. MODPOST 1 modulesWARNING: modpost: missing MODULE_LICENSE() in /root/桌面/kangear/module/hello.osee include/linux/module.h for more information CC /root/桌面/kangear/module/hello.mod.o LD [M] /root/桌面/kangear/module/hello.komake[1]: Leaving directory `/opt/kangear/kernel/linux-2.6.32.2'[[email protected] module]# lshello.c hello.mod.c hello.o modules.order paramhello.ko hello.mod.o Makefile Module.symvers symbol[[email protected] module]#
注意看hello.ko就出來了。
第二種錯誤:模組程式碼有異常
[[email protected] hello]# makemake -C /opt/kangear/kernel/linux-2.6.32.2 M=/opt/kangear/hello modulesmake[1]: Entering directory `/opt/kangear/kernel/linux-2.6.32.2' WARNING: Symbol version dump /opt/kangear/kernel/linux-2.6.32.2/Module.symvers is missing; modules will have no dependencies and modversions. CC [M] /opt/kangear/hello/hello.o/opt/kangear/hello/hello.c:3: error: expected declaration specifiers or '...' before string constant/opt/kangear/hello/hello.c:3: warning: data definition has no type or storage class/opt/kangear/hello/hello.c:3: warning: type defaults to 'int' in declaration of 'MODULE_LECENSE'/opt/kangear/hello/hello.c:3: warning: function declaration isn't a prototype/opt/kangear/hello/hello.c:17: error: redefinition of '__inittest'/opt/kangear/hello/hello.c:16: note: previous definition of '__inittest' was here/opt/kangear/hello/hello.c: In function '__inittest':/opt/kangear/hello/hello.c:17: warning: return from incompatible pointer type/opt/kangear/hello/hello.c: At top level:/opt/kangear/hello/hello.c:17: error: redefinition of 'init_module'/opt/kangear/hello/hello.c:16: note: previous definition of 'init_module' was heremake[2]: *** [/opt/kangear/hello/hello.o] 錯誤 1make[1]: *** [_module_/opt/kangear/hello] 錯誤 2make[1]: Leaving directory `/opt/kangear/kernel/linux-2.6.32.2'make: *** [default] 錯誤 2[[email protected] hello]# make
這大多是模組程式碼的錯誤,裡邊有中文相關的一些東西了,一些符號。程式碼是在部落格上拷貝的或者是在win下用ue編輯的,直接拷貝到Linux中就會有這種問題。唯一的辦法就是重新打一編程式碼了。目前還沒有找到合適的方法。(語法問題就不提了)
第三種:模組Makefile語法錯誤
[[email protected] hello]# makemake: Nothing to be done for `default'.[[email protected] hello]#
對應的makefile是命令為:
default:make -C $(KERNELDIR) M=$(PWD) modules
make前邊應該有一個tab鍵。或者是make前邊是空格而不是tab。