汇编程序消息:没有这样的指令:编译 C 时 'endbr64' - GCC 9.3.0,Ubuntu 20.04

Assembler messages: no such instruction: 'endbr64' when compiling C - GCC 9.3.0, Ubuntu 20.04

我正在尝试使用 gcc 在 C 中编译一个 hello world 程序

我正在使用 gcc 9.3.0 & ubuntu 20.04

这是我的c程序'hello.c'

#include<stdio.h>

int main() {

        printf("Hello World\n");

        return 0;
}

当我编译 gcc hello.c 时出现错误

/tmp/cc55wg43.s: Assembler messages:
/tmp/cc55wg43.s:12: Error: no such instruction: `endbr64'

已编辑:

我试过安装交叉编译器。为此,我安装了以下软件包 bison, flex, libgmp3-dev, libmpc-dev, libmpfr-dev, texinfo 我已经关注了 this!说明

附加 gcc -v hello.c

的输出
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/9/lto-wrapper
OFFLOAD_TARGET_NAMES=nvptx-none:hsa
OFFLOAD_TARGET_DEFAULT=1
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 9.3.0-17ubuntu1~20.04' --with-bugurl=file:///usr/share/doc/gcc-9/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++,gm2 --prefix=/usr --with-gcc-major-version-only --program-suffix=-9 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none=/build/gcc-9-HskZEa/gcc-9-9.3.0/debian/tmp-nvptx/usr,hsa --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04) 
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/9/cc1 -quiet -v -imultiarch x86_64-linux-gnu hello.c -quiet -dumpbase hello.c -mtune=generic -march=x86-64 -auxbase hello -version -fasynchronous-unwind-tables -fstack-protector-strong -Wformat -Wformat-security -fstack-clash-protection -fcf-protection -o /tmp/cc4rg9BM.s
GNU C17 (Ubuntu 9.3.0-17ubuntu1~20.04) version 9.3.0 (x86_64-linux-gnu)
    compiled by GNU C version 9.3.0, GMP version 6.2.0, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.22.1-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/9/include-fixed"
ignoring nonexistent directory "/usr/lib/gcc/x86_64-linux-gnu/9/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/lib/gcc/x86_64-linux-gnu/9/include
 /usr/local/include
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
GNU C17 (Ubuntu 9.3.0-17ubuntu1~20.04) version 9.3.0 (x86_64-linux-gnu)
    compiled by GNU C version 9.3.0, GMP version 6.2.0, MPFR version 4.0.2, MPC version 1.1.0, isl version isl-0.22.1-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: bbf13931d8de1abe14040c9909cb6969
COLLECT_GCC_OPTIONS='-v' '-mtune=generic' '-march=x86-64'
 as -v --64 -o /tmp/ccy9PKJM.o /tmp/cc4rg9BM.s
GNU assembler version 2.24 (x86_64-unknown-linux-gnu) using BFD version (GNU Binutils) 2.24
/tmp/cc4rg9BM.s: Assembler messages:
/tmp/cc4rg9BM.s:12: Error: no such instruction: `endbr64'

@AnttiHaapala 提到了这个问题: 根据说明要求您将前缀设置为 /usr/local/i386elfgcc - 也许您不小心将其从 binutils 配置中删除并在 /usr/bin 中安装了 binutils 而不是

解决方案是卸载 binutils 并重新安装

  • sudo apt-get remove binutils

    sudo apt-get remove --auto-remove binutils

    sudo apt install build-essential

现在binutils版本是2.34,之前是2.24

也许你的情况跟我一样:不小心安装了低版本的ld,没有删除干净。解决方法是删除旧的as,比如rm /usr/local/as