编译linux驱动时提示很多源码头文件和定义缺失

一、问题描述

        在写好驱动程序要编译的时候,出现以下错误提示(中间也有很多类似头文件和定义缺失的提示,篇幅问题没有放上来):

make -C /home/lzh/study_1/alientek-alpha/kernel-alientek M=/home/lzh/study_1/study_drivers/1_chardevbase modules
make[1]: Entering directory '/home/lzh/study_1/alientek-alpha/kernel-alientek'
  CC [M]  /home/lzh/study_1/study_drivers/1_chardevbase/chardevbase.o
In file included from ./arch/x86/include/asm/bitops.h:16:0,
                 from include/linux/bitops.h:36,
                 from include/linux/kernel.h:10,
                 from /home/lzh/study_1/study_drivers/1_chardevbase/chardevbase.c:2:
./arch/x86/include/asm/arch_hweight.h: In function ‘__arch_hweight64’:
./arch/x86/include/asm/arch_hweight.h:53:42: error: expected ‘:’ or ‘)’ before ‘POPCNT64’
  asm (ALTERNATIVE("call __sw_hweight64", POPCNT64, X86_FEATURE_POPCNT)
                                          ^
./arch/x86/include/asm/alternative.h:125:28: note: in definition of macro ‘ALTINSTR_REPLACEMENT’
  b_replacement(num)":\n\t" newinstr "\n" e_replacement(num) ":\n\t"
                            ^
./arch/x86/include/asm/arch_hweight.h:53:7: note: in expansion of macro ‘ALTERNATIVE’
  asm (ALTERNATIVE("call __sw_hweight64", POPCNT64, X86_FEATURE_POPCNT)
       ^
In file included from ./arch/x86/include/asm/pgtable_types.h:250:0,
                 from ./arch/x86/include/asm/processor.h:18,
                 from ./arch/x86/include/asm/thread_info.h:49,
                 from include/linux/thread_info.h:54,
                 from ./arch/x86/include/asm/preempt.h:6,
                 from include/linux/preempt.h:18,
                 from include/linux/spinlock.h:50,
                 from include/linux/seqlock.h:35,
                 from include/linux/time.h:5,
                 from include/uapi/linux/timex.h:56,
                 from include/linux/timex.h:56,
                 from include/linux/sched.h:19,
                 from include/linux/blkdev.h:4,
                 from include/linux/ide.h:12,
                 from /home/lzh/study_1/study_drivers/1_chardevbase/chardevbase.c:4:
include/asm-generic/pgtable-nopud.h: At top level:
include/asm-generic/pgtable-nopud.h:15:0: warning: "PUD_SHIFT" redefined
 #define PUD_SHIFT PGDIR_SHIFT
 ^
In file included from ./arch/x86/include/asm/pgtable_types.h:205:0,
                 from ./arch/x86/include/asm/processor.h:18,
                 from ./arch/x86/include/asm/thread_info.h:49,
                 from include/linux/thread_info.h:54,
                 from ./arch/x86/include/asm/preempt.h:6,
                 from include/linux/preempt.h:18,
                 from include/linux/spinlock.h:50,
                 from include/linux/seqlock.h:35,
                 from include/linux/time.h:5,
                 from include/uapi/linux/timex.h:56,
                 from include/linux/timex.h:56,
                 from include/linux/sched.h:19,
                 from include/linux/blkdev.h:4,
                 from include/linux/ide.h:12,
                 from /home/lzh/study_1/study_drivers/1_chardevbase/chardevbase.c:4:
./arch/x86/include/asm/pgtable_64_types.h:33:0: note: this is the location of the previous definition
 #define PUD_SHIFT 30
 ^

                                             ^
In file included from include/linux/sched.h:32:0,
                 from include/linux/blkdev.h:4,
                 from include/linux/ide.h:12,
                 from /home/lzh/study_1/study_drivers/1_chardevbase/chardevbase.c:4:
include/linux/cputime.h:4:25: fatal error: asm/cputime.h: 没有那个文件或目录
compilation terminated.
scripts/Makefile.build:264: recipe for target '/home/lzh/study_1/study_drivers/1_chardevbase/chardevbase.o' failed
make[2]: *** [/home/lzh/study_1/study_drivers/1_chardevbase/chardevbase.o] Error 1
Makefile:1384: recipe for target '_module_/home/lzh/study_1/study_drivers/1_chardevbase' failed
make[1]: *** [_module_/home/lzh/study_1/study_drivers/1_chardevbase] Error 2
make[1]: Leaving directory '/home/lzh/study_1/alientek-alpha/kernel-alientek'
Makefile:9: recipe for target 'kernel_modules' failed
make: *** [kernel_modules] Error 2
lzh@ubuntu16:~/study_1/study_drivers/1_chardevbase$ make
make -C /home/lzh/study_1/alientek-alpha/kernel-alientek M=/home/lzh/study_1/study_drivers/1_chardevbase modules
make[1]: Entering directory '/home/lzh/study_1/alientek-alpha/kernel-alientek'
Makefile:610: arch//Makefile: 没有那个文件或目录
make[1]: *** No rule to make target 'arch//Makefile'。 停止。
make[1]: Leaving directory '/home/lzh/study_1/alientek-alpha/kernel-alientek'
Makefile:9: recipe for target 'kernel_modules' failed
make: *** [kernel_modules] Error 2

但是我的Makefile文件十分简单,应该没有什么问题:

KERNELDIR :=/home/lzh/study_1/alientek-alpha/kernel-alientek
CURRENT_PATH := $(shell pwd)
ENV:=ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-
obj-m :=chardevbase.o

build :kernel_modules

kernel_modules:
	$(MAKE) -C $(KERNELDIR) M=$(CURRENT_PATH) modules
clean:
	$(MAKE) -C $(KERNELDIR) M=$(CURRENT_PATH) clean

二、问题解决

找到用于编译驱动模块的linux源码,进入它的Makefile文件,进行如下修改:

在大概255行的地方:

将:

ARCH		    ?= $(SUBARCH)
CROSS_COMPILE	?= $(CONFIG_CROSS_COMPILE:"%"=%)

改为:

ARCH		?= arm
CROSS_COMPILE	?= arm-linux-gnueabihf-

注意:

1、这边重新定义的值是没有括号的了。

2、由于我用的是arm-linux-gnueabihf这个交叉编译器,所以这里修改为它,使用其他编译器的话记得进行对应修改。

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值