一、cc1: error: code model kernel does not support PIC mode
原因:主机的gcc版本,和开发板的gcc工具版本不一致。需要指定gcc开发板工具的gcc
解决办法:编写Makefile文件的时候指定gcc工具
Makefile文件中指定gcc如下:
ifeq ($(HOST), ubuntu)
#ubuntu内核
KERNEL_DIR:=/usr/src/linux-headers-$(shell uname -r)
CC:=gcc
else
KERNELDIR:= /home/cw1111/arm_ubuntu/linux-cortexm-2.4.0/linux
CC:=$(CROSS_COMPILE)gcc #指定开发板路径上的工具gcc
二、再次编译模块,出现了问题error: variable ‘__this_module’ has initializer but incomplete type
原因在编译内核文件时候,在进行配置设置(General setup)的时候,没有勾线Enable loadable module support
/home/cw1111/GCC/dirver/chardevbase.mod.c:8: error: variable ‘__this_module’ has initializer but incomplete type
/home/cw1111/GCC/dirver/chardevbase.mod.c:9: error: unknown field ‘name’ specified in initializer
/home/cw1111/GCC/dirver/chardevbase.mod.c:9: warning: excess elements in struct initializer
/home/cw1111/GCC/dirver/chardevbase.mod.c:9: warning: (near initialization for ‘__this_module’)
/home/cw1111/GCC/dirver/chardevbase.mod.c:10: error: unknown field ‘init’ specified in initializer
/home/cw1111/GCC/dirver/chardevbase.mod.c:10: warning: excess elements in struct initializer
/home/cw1111/GCC/dirver/chardevbase.mod.c:10: warning: (near initialization for ‘__this_module’)
/home/cw1111/GCC/dirver/chardevbase.mod.c:14: error: unknown field ‘arch’ specified in initializer
/home/cw1111/GCC/dirver/chardevbase.mod.c:14: error: ‘MODULE_ARCH_INIT’ undeclared here (not in a function)
/home/cw1111/GCC/dirver/chardevbase.mod.c:14: warning: excess elements in struct initializer
/home/cw1111/GCC/dirver/chardevbase.mod.c:14: warning: (near initialization for ‘__this_module’)
scripts/Makefile.modpost:113: recipe for target ‘/home/cw1111/GCC/dirver/chardevbase.mod.o’ failed…
解决办法
执行:make menuconfig
执行make menuconfig 命令又出现了新的问题
<command-line>:0:12: fatal error: curses.h: 没有那个文件或目录
这时因为ubuntu系统中缺少一个套件 ncurses devel ,没有就去下载:
执行:
apt-get install libncurses5-dev
对于 apt-get install libncurses5-dev总是失败的看compiler-gcc5.h源码
再次执行:make menuconfig
终于出现了久违的设置框了,选上Enable loadable module support。
重新编译内核。
激动人心的时候到了:
编译我们的驱动文件:make:
make -C /home/cw1111/arm_ubuntu/linux-cortexm-2.4.0/linux M=/home/cw1111/GCC/dirver modules
make[1]: 进入目录“/home/cw1111/arm_ubuntu/linux-cortexm-2.4.0/linux”
CC [M] /home/cw1111/GCC/dirver/chardevbase.o
Building modules, stage 2.
MODPOST 1 modules
CC /home/cw1111/GCC/dirver/chardevbase.mod.o
LD [M] /home/cw1111/GCC/dirver/chardevbase.ko
make[1]: 离开目录“/home/cw1111/arm_ubuntu/linux-cortexm-2.4.0/linux”