Cabal安装(Cabal cabal-install)失败,因为缺少zlib库。

9

我想在Ubuntu 20.04上安装Cabal 3.4.0.0。

$ sudo apt install cabal-install
$ cabal --version
cabal-install version 2.4.0.0

$ sudo cabal update
$ sudo cabal install Cabal cabal-install
...
Starting     zlib-0.6.2.3
Failed to install zlib-0.6.2.3
Build log ( /root/.cabal/logs/ghc-8.6.5/zlib-0.6.2.3-93Wbo8gIIzI9bg4p2MsNUF.log ):
cabal: Entering directory '/tmp/cabal-tmp-126381/zlib-0.6.2.3'
Configuring zlib-0.6.2.3...
cabal: Missing dependency on a foreign library:
* Missing (or bad) header file: zlib.h
* Missing (or bad) C library: z
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.If the
library file does exist, it may contain errors that are caught by the C
compiler at the preprocessing stage. In this case you can re-run configure
with the verbosity flag -v3 to see the error messages.
If the header file does exist, it may contain errors that are caught by the C
compiler at the preprocessing stage. In this case you can re-run configure
with the verbosity flag -v3 to see the error messages.
...
cabal: Error: some packages failed to install:
cabal-install-3.4.0.0-3glzV3hM64DLoOfz3dHKsn depends on cabal-install-3.4.0.0
which failed to install.
hackage-security-0.6.0.1-KiAyVYLxooJAP3ckeQHnBD depends on
hackage-security-0.6.0.1 which failed to install.
zlib-0.6.2.3-93Wbo8gIIzI9bg4p2MsNUF failed during the configure step. The
exception was:
ExitFailure 1

错误提示如下:

通常可以通过安装提供该库的系统软件包来解决此问题(您可能需要安装"-dev"版本)。

在Ubuntu 20.04上我应该如何安装这个软件包呢?


5
安装 zlib1g-dev,需在终端输入命令:sudo apt-get install zlib1g-dev。 - Willem Van Onsem
@WillemVanOnsem 谢谢,这个方法很有效!您是如何找到这些信息的(这样我下次也可以自己找到)? - eddex
2
命令apt-cache非常有用。尝试使用“apt-cache search zlib”命令。请参见相关SE问题 - jpmarinier
@WillemVanOnsem,您应该将您的评论发布为答案,这样才能被接受。 - sclv
2个回答

9
您希望安装 cabal-install,但该包依赖于另一个包zlib,使得安装出现问题。 zlib 包实质上是一个细包装器,包含了zlib C 库 [维基百科]。但错误提示表明,您未安装 zlib 库,至少没有安装开发需要的 zlib 库的包。
例如,我们可以通过安装 libghc-zlib-dev 软件包 来解决这个问题。
sudo apt-get install <strong>libghc-zlib-dev</strong>

如果我们检查一下在Debian上的软件包详情(package details on Debian),我们就可以看到,这本质上是一个安装zlib1g-dev软件包的软件包,用于开发使用zlib库的软件。因此,我们可以决定使用以下命令安装libghc-zlib-devzlib1g-dev:
sudo apt-get install <strong>zlib1g-dev</strong>

sudo apt-get install zlib1g-dev 没有效果,但是 sudo apt-get install libghc-zlib-dev 成功了,谢谢。 - Andreas Röhler

1
NixOS用户需要将pkgs.haskellPackages.zlib添加到environment.systemPackages中。

目前你的回答不够清晰,请编辑并添加更多细节,以帮助其他人理解它如何回答问题。你可以在帮助中心找到有关如何编写好答案的更多信息。 - Community

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