【已解决】编译Linux内核报错multiple definition of yylloc
问题描述
在学习正点原子的驱动开发指南过程中,在编译Linux内核时出现以下报错,内核文件为:linux-imx-rel_imx_4.1.15_2.1.0_ga。
./mx6ull_alientek_emmc.sh文件内容如下
#!/bin/sh
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- distclean
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- imx_v7_defconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- menuconfig
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- all -j16
报错信息如下:
In file included from include/linux/kernel.h:11,from include/asm-generic/bug.h:13,from ./arch/arm/include/asm/bug.h:61,from include/linux/bug.h:4,from include/linux/page-flags.h:9,from kernel/bounds.c:9:
include/linux/log2.h:22:1: warning: ignoring attribute ‘noreturn’ because it conflicts with attribute ‘const’ [-Wattributes]22 | int ____ilog2_NaN(void);| ^~~CHK include/generated/bounds.hUPD include/generated/bounds.hCC arch/arm/kernel/asm-offsets.s
In file included from include/linux/kernel.h:11,from include/linux/sched.h:17,from arch/arm/kernel/asm-offsets.c:14:
include/linux/log2.h:22:1: warning: ignoring attribute ‘noreturn’ because it conflicts with attribute ‘const’ [-Wattributes]22 | int ____ilog2_NaN(void);| ^~~CHK include/generated/asm-offsets.hUPD include/generated/asm-offsets.hCALL scripts/checksyscalls.shHOSTLD scripts/dtc/dtc
/usr/bin/ld: scripts/dtc/dtc-parser.tab.o:(.bss+0x50): multiple definition of yylloc'; scripts/dtc/dtc-lexer.lex.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status
make[2]: *** [scripts/Makefile.host:100:scripts/dtc/dtc] 错误 1
make[1]: *** [scripts/Makefile.build:403:scripts/dtc] 错误 2
make[1]: *** 正在等待未完成的任务....HOSTLD scripts/genksyms/genksymsHOSTLD scripts/mod/modpost
make: *** [Makefile:556:scripts] 错误 2
make: *** 正在等待未完成的任务....
txj@txj-virtual-machine:~/IMX6ULL/linux_core/linux-imx-rel_imx_4.1.15_2.1.0_ga$
解决方案
先后尝试过将gcc-12版本重装为gcc-9版本,运行后出现更多错误。以及在/scripts/dtc/dtc-lexer.lex.c文件中对YYLTYPE yylloc; + extern 变为extern YYLTYPE yylloc; 无效。
最后通过以下办法解决问题:
重新下载了arm-linux-gnueabihf-gcc
gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf.tar
通过百度网盘分享的文件:gcc-linaro-4.9.4-2017.01-x86_64_arm...
链接:https://pan.baidu.com/s/1tdF7qalld4E86S3kc9-dAQ?pwd=us5v
提取码:us5v
--来自百度网盘超级会员V5的分享
步骤如下:
将文件拷贝到Ubuntu根目录下的tools文件中sudo mkdir /usr/local/armsudo cp gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf.tar.xz /usr/local/arm/ -fsudo tar -vxf gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf.tar.xzsudo vi /etc/profileexport PATH=$PATH:/usr/local/arm/gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf/binsudo apt-get install lsb-core lib32stdc++6sudo rebootarm-linux-gnueabihf-gcc -v
gcc版本为下图,为安装成功。

这个时候再运行一次./mx6ull_alientek_emmc.sh 应该就能够正常编译了。
如果gcc版本还是原来的,需要先删除先前的 arm-linux-gnueabihf-gcc再重新进行上面的步骤。
which arm-linux-gnueabihf-gcc-<version>,找到文件的路径,备份一下,然后删除它即可。
