使用的是Ubuntu22.04 编译的时候出现上面的错误
很多回答都是sudo apt-get install libpng-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:
libpng-dev : Depends: libpng16-16 (= 1.6.34-1ubuntu0.18.04.2) but 1.6.37-3build5 is to be installed
Recommends: libpng-tools but it is not going to be installed
E: Unable to correct problems, you have held broken packages.
```
咱就说 这个报错没有看明白 后面就对着这个报错去搜索解决方法了
在这个链接中有一个方法
ubuntu - How do I resolve `The following packages have unmet dependencies` - Stack Overflow
最高赞是通过aptitude解决 “unmet dependencies”这个问题
后面我就通过下面的步骤使用了aptitude
先安装aptitude
sudo apt-get install aptitude
然后通过aptitude再次尝试安装需要的包
也就是下面这样
sudo aptitude install libpng-dev
然后就是这条命令对应的交互
The following NEW packages will be installed:
libpng-dev{b}
0 packages upgraded, 1 newly installed, 0 to remove and 1 not upgraded.
Need to get 177 kB of archives. After unpacking 609 kB will be used.
The following packages have unmet dependencies:
libpng-dev : Depends: libpng16-16 (= 1.6.34-1ubuntu0.18.04.2) but 1.6.37-3build5 is installed
The following actions will resolve these dependencies:
Keep the following packages at their current version:
1) libpng-dev [Not Installed]
Accept this solution? [Y/n/q/?] n
The following actions will resolve these dependencies:
Downgrade the following packages:
1) libpng16-16 [1.6.37-3build5 (now) -> 1.6.34-1ubuntu0.18.04.2 (bionic-security, bionic-updates)]
Accept this solution? [Y/n/q/?] Y
The following packages will be DOWNGRADED:
libpng16-16
The following NEW packages will be installed:
libpng-dev
0 packages upgraded, 1 newly installed, 1 downgraded, 0 to remove and 1 not upgraded.
Need to get 353 kB of archives. After unpacking 574 kB will be used.
Do you want to continue? [Y/n/?] Y
Get: 1 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 libpng16-16 amd64 1.6.34-1ubuntu0.18.04.2 [176 kB]
Get: 2 http://mirrors.aliyun.com/ubuntu bionic-security/main amd64 libpng-dev amd64 1.6.34-1ubuntu0.18.04.2 [177 kB]
Fetched 353 kB in 0s (747 kB/s)
dpkg: warning: downgrading libpng16-16:amd64 from 1.6.37-3build5 to 1.6.34-1ubuntu0.18.04.2
(Reading database ... 51415 files and directories currently installed.)
Preparing to unpack .../libpng16-16_1.6.34-1ubuntu0.18.04.2_amd64.deb ...
Unpacking libpng16-16:amd64 (1.6.34-1ubuntu0.18.04.2) over (1.6.37-3build5) ...
Selecting previously unselected package libpng-dev:amd64.
Preparing to unpack .../libpng-dev_1.6.34-1ubuntu0.18.04.2_amd64.deb ...
Unpacking libpng-dev:amd64 (1.6.34-1ubuntu0.18.04.2) ...
Setting up libpng16-16:amd64 (1.6.34-1ubuntu0.18.04.2) ...
Setting up libpng-dev:amd64 (1.6.34-1ubuntu0.18.04.2) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...
Processing triggers for man-db (2.10.2-1) ...
最主要的就是第一次选择n 第二次选择Y 这样会让aptitude将已经存在的libpng16-16回退到需要的版本
有一说一 通过最开始的安装报错我是真没有看出来是因为要安装的包在本地已经有更新的版本导致安装失败