linux内核编译错误

Posted 九章_

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了linux内核编译错误相关的知识,希望对你有一定的参考价值。

项目场景:

linux内核编译错误

问题描述:

 CC [M]  /home/wyong/imx6ull/1_chrdevbase/chrdevbase.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/wyong/imx6ull/1_chrdevbase/chrdevbase.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/wyong/imx6ull/1_chrdevbase/chrdevbase.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,
./arch/x86/include/asm/cache.h:7:25: error: ‘CONFIG_X86_L1_CACHE_SHIFT’ undeclared here (not in a function)
 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
                         ^
./arch/x86/include/asm/cache.h:8:30: note: in expansion of macro ‘L1_CACHE_SHIFT’
 #define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
                              ^
include/linux/cache.h:12:25: note: in expansion of macro ‘L1_CACHE_BYTES’
 #define SMP_CACHE_BYTES L1_CACHE_BYTES
                         ^
include/linux/cache.h:20:58: note: in expansion of macro ‘SMP_CACHE_BYTES’
 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
                                                          ^
./arch/x86/include/asm/processor.h:270:27: note: in expansion of macro ‘____cacheline_aligned’
 } __attribute__((packed)) ____cacheline_aligned;

./arch/x86/include/asm/processor.h: In function ‘current_top_of_stack’:
./arch/x86/include/asm/processor.h:594:30: error: ‘cpu_current_top_of_stack’ undeclared (first use in this function)
  return this_cpu_read_stable(cpu_current_top_of_stack);
                              ^
./arch/x86/include/asm/percpu.h:213:9: note: in definition of macro ‘percpu_stable_op’
  typeof(var) pfo_ret__;    \\
         ^
./arch/x86/include/asm/processor.h:594:9: note: in expansion of macro ‘this_cpu_read_stable’
  return this_cpu_read_stable(cpu_current_top_of_stack);
         ^
./arch/x86/include/asm/processor.h:594:30: note: each undeclared identifier is reported only once for each function it appears in
  return this_cpu_read_stable(cpu_current_top_of_stack);
                              ^
./arch/x86/include/asm/percpu.h:213:9: note: in definition of macro ‘percpu_stable_op’
  typeof(var) pfo_ret__;    \\
         ^

./arch/x86/include/asm/atomic64_64.h:207:45: error: unknown type name ‘atomic64_t’
 static inline long atomic64_dec_if_positive(atomic64_t *v)
                                             ^
In file included from include/linux/sched.h:32:0,
                 from include/linux/blkdev.h:4,
                 from include/linux/ide.h:12,
                 from /home/wyong/imx6ull/1_chrdevbase/chrdevbase.c:4:
include/linux/cputime.h:4:25: fatal error: asm/cputime.h: No such file or directory
compilation terminated.
scripts/Makefile.build:264: recipe for target '/home/wyong/imx6ull/1_chrdevbase/chrdevbase.o' failed
make[2]: *** [/home/wyong/imx6ull/1_chrdevbase/chrdevbase.o] Error 1
Makefile:1384: recipe for target '_module_/home/wyong/imx6ull/1_chrdevbase' failed
make[1]: *** [_module_/home/wyong/imx6ull/1_chrdevbase] Error 2

原因分析与解决方法:

怀疑是编译器的问题,在执行make时没有找到指定的编译器,做了实现验证编译器能不能使用,验证是可以的。在命令行中增加

ARCH=arm
CROSS_COMPILE=arm-linux-gnueabi-

然后在执行make仍然有错误

1)在命令行下执行,这样是可以编译的

make  ARCH=arm  CROSS_COMPILE=arm-linux-gnueabi-   

2)在Makefile中添加变量,在编译(CC)阶段,使用这个变量


MAKE_ENV := ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf-
...
$(CC)  $(MAKE_ENV)  

以上是关于linux内核编译错误的主要内容,如果未能解决你的问题,请参考以下文章

linux编译内核时出现错误,求解

Linux 0.11内核编译错误记录

linux内核编译错误

编译linux内核2.4.0时内联汇编错误

错误记录编译 Linux 内核报错 ( /bin/sh: 1: bison: not found )

Linux 4.4 内核更改