debain12 /usr/bin/ld: cannot find Scrt1.o

我正在debian12中尝试编译qemu,出现如下报错:

-----------
stderr:
collect2 version 12.2.0
/usr/bin/ld -plugin /usr/lib/gcc/x86_64-linux-gnu/12/liblto_plugin.so -plugin-opt=/usr/lib/gcc/x86_64-linux-gnu/12/lto-wrapper -plugin-opt=-fresolution=/tmp/cc8R6EvL.res -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s -plugin-opt=-pass-through=-lc -plugin-opt=-pass-through=-lgcc -plugin-opt=-pass-through=-lgcc_s --build-id --eh-frame-hdr -m elf_x86_64 --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 -pie Scrt1.o crti.o /usr/lib/gcc/x86_64-linux-gnu/12/crtbeginS.o -L/usr/lib/gcc/x86_64-linux-gnu/12 -L/usr/lib/gcc/x86_64-linux-gnu/12/../../../x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/12/../../../../lib -L/lib/x86_64-linux-gnu -L/lib/../lib -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib -L/usr/lib/gcc/x86_64-linux-gnu/12/../../.. --version -lgcc --push-state --as-needed -lgcc_s --pop-state -lc -lgcc --push-state --as-needed -lgcc_s --pop-state /usr/lib/gcc/x86_64-linux-gnu/12/crtendS.o crtn.o
-----------
Sanity testing C compiler: cc -m64
Is cross compiler: False.
Sanity check compiler command line: cc -m64 sanitycheckc.c -o sanitycheckc.exe -D_FILE_OFFSET_BITS=64
Sanity check compile stdout:

-----
Sanity check compile stderr:
/usr/bin/ld: cannot find Scrt1.o: No such file or directory
/usr/bin/ld: cannot find crti.o: No such file or directory
collect2: error: ld returned 1 exit status

-----

../meson.build:1:0: ERROR: Compiler cc -m64 cannot compile programs.

提示没有 Scrt1.o和 crti.o,于是我尝试安装libc6-dev 但是提示libc6的版本不匹配

sudo apt install libc6-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:

The following packages have unmet dependencies:
 libc6-dev : Depends: libc6 (= 2.36-9+deb12u10) but 2.41-7 is to be installed
             Depends: libc-dev-bin (= 2.36-9+deb12u10) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.

这个问题有人遇到过吗,这里说的应该是我的libc6版本更新一点,我觉得强制安装老的版本可能会有问题,不知道有没有更好的解决方式…

首先:永远永远不要操纵系统 libc 的版本,试着安装和当前系统 libc 版本不同的新版本或旧版本 libc 必定炸,没有例外。

其次:在2025年7月查看 Debian 提供的 libc6 版本:

-> % rmadison libc6 
libc6      | 2.28-10+deb10u1  | oldoldstable      | amd64, arm64, armhf, i386
libc6      | 2.31-13+deb11u5  | oldstable-updates | amd64, arm64, armel, armhf, i386, mips64el, mipsel, ppc64el, s390x
libc6      | 2.31-13+deb11u11 | oldstable         | amd64, arm64, armel, armhf, i386, mips64el, mipsel, ppc64el, s390x
libc6      | 2.36-9+deb12u10  | stable            | amd64, arm64, armel, armhf, i386, mips64el, mipsel, ppc64el, s390x
libc6      | 2.36-9+deb12u12  | proposed-updates  | amd64, arm64, armel, armhf, i386, mips64el, mipsel, ppc64el, s390x
libc6      | 2.41-9           | testing           | amd64, arm64, armel, armhf, i386, ppc64el, riscv64, s390x
libc6      | 2.41-9           | unstable          | amd64, arm64, armel, armhf, i386, mips64el, ppc64el, riscv64, s390x

从其中可以发现 Debian 12 提供 2.36-9 版本, Debian 11 提供 2.31-13 版本。那么你的输出中 2.41 从哪里来的?难道是还没发布的 Debian 13?

这只能说明你用着 Debian 12 但启用了 Debian 13 的软件源,如果混搭且已经安装了部分新软件那很可能系统已经炸了。

我的建议:如果已经混搭并装过新版软件的话那请重装系统,避免浪费时间 debug。如果尚未装新版软件请把你的 Debian 13 软件源抹掉只留 Debian 12 自己的软件源。如无需高级操作,请只在 Debian 12 系统上启用 Debian 12 的软件源,只在 Debian 13 系统上中启用 Debian 13 的软件源,不要混搭。

感谢您的回复,我看了下我的软件源,似乎没什么异常? 不知道我这个2.41版本的libc是从哪来的…

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm main contrib non-free non-free-firmware

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-updates main contrib non-free non-free-firmware

deb https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware
deb-src https://mirrors.tuna.tsinghua.edu.cn/debian/ bookworm-backports main contrib non-free non-free-firmware

然后我想既然2.36是debian12应该安装的版本,那我再把它强制回退回来是不是也还好?

关于:

如果尚未装新版软件请把你的 Debian 13 软件源抹掉只留 Debian 12 自己的软件源。

这点您有什么建议或者可以简单指导一下吗,我怕自己弄不好会出问题 :sweat_smile:

尽管会有很多麻烦的事情,如果实在没有其他办法的话,我会考虑重装系统…

看一下 apt policy libc6apt policy libc6-dev 的输出。如果你的软件源确实配错了,这些输出会显示不正确的候选版本(例如 2.41 的 glibc)。然后你就可以在系统里寻找是否有额外的 sources.list 文件写入了不正确版本。