安裝 libc-dev 時遇到問題

安裝 libc-dev 時遇到問題

當我嘗試在 Ubuntu 上編譯 C 程式時,出現此錯誤:

$ gcc aa.c
aa.c:1:9: fatal error: stdio.h: No such file or directory
 #include<stdio.h>
         ^--------
compilation terminated.

我嘗試安裝libc6-dev並得到了這個:

$ sudo apt-get install libc6-dev
...
The following packages have unmet dependencies:
 libc6-dev : Depends: libc6 (= 2.27-3ubuntu1) but 2.29-10 is to be installed
             Depends: libc-dev-bin (= 2.27-3ubuntu1)
E: Unable to correct problelms, you have held broken packages.

我已經嘗試過: sudo dpkg --configure -a,但沒有任何輸出。

sudo apt-get install -f

sudo apt-get clean && sudo apt-get update

sudo apt-get upgrade

sudo apt-get dist-upgrade

以上四個程式碼得到相同的輸出:

0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

使用所有這些命令後,我在編譯時遇到相同的致命錯誤。

apt policy libc6-dev libc6

輸出:

libc6-dev:
  Installed: (none)
  Candidate: 2.27-3ubuntu1
  Version table:
     2.27-3ubuntu1 500
        500 http://in.archive.ubuntu.com/ubuntu bionic/main amd64 Packages
libc6:
  Installed: 2.29-10
  Candidate: 2.29-10
  Version table:
 *** 2.29-10 100
        100 /var/lib/dpkg/status
     2.27-3ubuntu1 500
        500 http://in.archive.ubuntu.com/ubuntu bionic/main amd64 Packages

答案1

不知何故,您最終得到了當前的 Debian 測試版本libc6,而不是任何 Ubuntu 版本。想必這是有原因的,所以改變它可能會破壞某些東西。

此時你有兩個選擇:

  • 降級libc6到Ubuntu版本:

    sudo apt install libc6=2.27-3ubuntu1
    

    這還需要降級相關的軟體包(apt會告訴你哪些,但我想你至少有libc-binlocales

    或者

  • 安裝 Debian 測試libc6-dev套件:

    wget http://ftp.fr.debian.org/debian/pool/main/g/glibc/libc6-dev_2.29-10_amd64.deb http://ftp.fr.debian.org/debian/pool/main/g/glibc/libc6-dev-bin_2.29-10_amd64.deb
    sudo apt install ./libc6-dev_2.29-10_amd64.deb ./libc6-dev-bin_2.29-10_amd64.deb
    

我建議恢復到 Ubuntu 版本,即使只是為了讓你的下一個發行版升級更簡單,但這可能會產生其他更直接的後果。

相關內容