在编译linux内核时,编译报错
usr/bin/ld: scripts/dtc/dtc-parser.tab.o:(.bss+0x10): multiple definition of 'yylloc'; scripts/dtc/dtc-lexer.lex.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status
解决方法 1:【此方法我没有走通】
edit the file ./linux-rtk/scripts/dtc/dtc-lexer-lex.c Find the line
‘YYLTYPE yylloc’ and change it to ‘extern YYLTYPE yylloc’
解决方法 2:【此方法可用】
因为gcc的版本比较高,与当前的ubuntu系统不兼容,所以需要降低gcc版本。我当时编译报错时,用的是gcc-11,需要将gcc版本降到gcc-9.
当前版本查询:
查看当前的gcc版本:gcc --version
查看当前的g++版本:g++ --version
gcc版本降级:
查看已安装的gcc版本: ls /usr/bin/gcc*
如果版本中没有9版本,则安装:sudo apt-get install gcc-9
将9版本的优先级提高: sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-9 100
【上面中的100,指的是优先级,不一定是100,也可以是其他值,数值越大,优先级越高】