在Ubuntu 20.04上安装libgtk-3-dev

7

我想用cpp写一个GUI程序。据我所知,gtk是一个不错的解决方案。但不幸的是,在Ubuntu 20.04上似乎无法使用gtk了。(如果有关系的话)我正在使用Xubuntu。

执行以下命令:sudo apt install libgtk-3-dev

会导致:

Reading package lists... Done
Building dependency tree       
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:
 libgtk-3-dev : Depends: gir1.2-gtk-3.0 (= 3.24.20-0ubuntu1) but 3.24.20-1 is to be installed
                Depends: libatk-bridge2.0-dev but it is not going to be installed
                Depends: libatk1.0-dev (>= 2.15.1) but it is not going to be installed
                Depends: libcairo2-dev (>= 1.14.0) but it is not going to be installed
                Depends: libfontconfig1-dev but it is not going to be installed
                Depends: libgdk-pixbuf2.0-dev (>= 2.40.0) but it is not going to be installed
                Depends: libglib2.0-dev (>= 2.57.2) but it is not going to be installed
                Depends: libpango1.0-dev (>= 1.41) but it is not going to be installed
                Depends: libxi-dev but it is not going to be installed
                Depends: libgtk-3-0 (= 3.24.20-0ubuntu1) but 3.24.20-1 is to be installed
E: Unable to correct problems, you have held broken packages.

我按照建议添加了 "deb http://archive.ubuntu.com/ubuntu focal-updates main" ,然后再次尝试,结果如下:

Reading package lists... Done
Building dependency tree       
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:
 libgtk-3-dev : Depends: libatk-bridge2.0-dev but it is not going to be installed
                Depends: libatk1.0-dev (>= 2.15.1) but it is not going to be installed
                Depends: libcairo2-dev (>= 1.14.0) but it is not going to be installed
                Depends: libfontconfig1-dev but it is not going to be installed
                Depends: libgdk-pixbuf2.0-dev (>= 2.40.0) but it is not going to be installed
                Depends: libglib2.0-dev (>= 2.57.2) but it is not going to be installed
                Depends: libpango1.0-dev (>= 1.41) but it is not going to be installed
                Depends: libxi-dev but it is not going to be installed
                Depends: libgtk-3-0 (= 3.24.20-0ubuntu1) but 3.24.20-1 is to be installed
E: Unable to correct problems, you have held broken packages.

我正在寻找一个安装libgtk-3-dev的解决方案。


我卸载了girl1.2-gtk-3.0并重新安装,现在它已经不在列表中了。无论如何...卸载girl1.2-gtk-3.0也卸载了许多其他软件包。有没有办法将所有这些软件包与girl1.2-gtk-3.0一起重新安装(我现在通过手动重新安装每个软件包来解决了这个问题)? - Natan
自己注意:仔细阅读,如果你不打算构建 Linux 桌面应用程序,则无需安装它们。 - M Imam Pratama
2个回答

10
问题是适当版本的libgtk-3-dev库和相关依赖项尚未在主要的focal存储库中。我的解决方案是添加focal-updates存储库。您可以通过GUI(软件和更新)或手动编辑文件来完成。
/etc/apt/sources.list

添加以下行:
deb http://archive.ubuntu.com/ubuntu focal-updates main

如果你是从命令行工作的话,可能需要更新存储库列表。
sudo apt update

然后我成功安装了这个库(我使用了Synaptic管理器),没有遇到任何问题。 最后,我禁用了focal-updates仓库,保持之前只使用发布仓库的状态,不会自动更新其他尚未发布的库。

1
嗨,你能解释一下为什么留在"main"很重要吗?添加存储库并不听起来像是"非主",因为它的名称中有"main"。虽然我不太了解这方面的内容,但是到目前为止你的回答看起来对我来说是个解决方案 :) - Natan
1
我已经纠正了最后一句话。它只是要留在稳定版本的存储库中。否则,它可能会自动更新其他东西,我想。但也许我错了。请参见Ubuntu存储库描述,例如:ubuntu.se - Bartolomejka
1
谢谢!这至少从未满足的依赖项列表中移除了一项。可惜它仍然无法工作。我将结果添加到问题中,以便每个人都可以看到当前状态。 - Natan
1
谢谢!你救了我一天!它也适用于Ubuntu 22...但我想知道为什么如果它是一个主要的软件包更新,那么它会被排除在默认的Ubuntu安装之外?Ubuntu很好,但有时也很疯狂...下次我会回到Debian并在我的笔记本电脑上安装它。 - Carlos Saltos
1
更改/etc/apt/sources.list后,需要执行sudo apt update命令来应用仓库的更改。这个解决方案适用于Ubuntu 20.04。谢谢! - undefined

0

首先,我会确保我拥有所有所需的依赖项,并确保安装所需的特定版本。这些依赖项可以在Ubuntu网站上找到。

如果在apt存储库中找不到依赖项,则可以从各自的网站上下载每个缺失软件包的源文件,并从源代码构建libgtk。

您很可能安装了与其他所需软件不兼容的软件包,但是需要更深入挖掘才能找到根本原因。


这些软件包无法安装,因为它们有未满足的依赖关系... libcairo libatk libgdk-pixbuf2.0-dev libglib2.0-dev libpango1.0-dev libxi-dev。其余的已经安装好了。我认为这并没有什么帮助,因为如果它们可以自动安装,Ubuntu会自己完成的。 - Natan
它也失败了,因为缺少依赖项。你正在运行ubuntu20.04或者其他操作系统吗? - Natan
是的,我正在运行Ubuntu 20.04,它是“Focal”版本。你的环境肯定出了些问题,很可能是破损的软件包。你可以尝试使用命令dpkg -C检查是否有破损的软件包,或者尝试运行命令dpkg --configure -a以防止更新中断。 - pseudovella
我猜你可能已经尝试过这个或类似的方法,但尝试执行 apt-get clean ; apt-get update; apt-get -f install 命令通常会有所帮助。 - pseudovella
你提到的所有命令都没有或者没有有意义的输出。dpkg -C,dpkg --configure -a(我之前尝试过)也没有输出,clean 没有输出,update 像往常一样,-f 也没有改变结果。apt-mark showhold 是空的。 - Natan
显示剩余3条评论

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接