【问题标题】:Finding foreign library with cabal using nix-shell使用 nix-shell 查找带有 cabal 的外国图书馆
【发布时间】:2019-04-07 06:18:52
【问题描述】:

我有类似的问题:Cabal can't find foreign library when building on NixOS

基本上我使用 cabal2nix 从包含以下内容的 package.yaml 生成:

extra-libraries:
  - libmnl

这会产生一个 cabal.nix 文件:

{ mkDerivation, base, bytestring, cereal, containers, hpack
, iproute, lens, libmnl, netlink, primitive
, resourcet, safe-exceptions, stdenv, transformers
}:
mkDerivation {
  pname = "relay";
  version = "0.1.0.0";
  src = ./.;
  libraryHaskellDepends = [
    base bytestring cereal containers iproute lens netlink
    primitive resourcet safe-exceptions transformers
  ];
  librarySystemDepends = [ libmnl ];
  libraryToolDepends = [ hpack ];
  testHaskellDepends = [
    base bytestring cereal containers iproute lens netlink
    primitive resourcet safe-exceptions transformers
  ];
  testSystemDepends = [ libmnl ];
  preConfigure = "hpack";
  homepage = "https://github.com/MatrixAI/Relay#readme";
  license = stdenv.lib.licenses.asl20;
}

如果我通过nix-shell 进入,然后运行cabal configure。它抱怨找不到 libmnl:

Resolving dependencies...
Configuring relay-0.1.0.0...
cabal: Missing dependency on a foreign library:
* Missing (or bad) C library: libmnl
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.

还在nix-shell 内的这个文件上运行gcc -c test.c -lmnl 有效:

#include <libmnl/libmnl.h>

int main() { return 0; }

那么为什么 cabal 找不到 libmnlgcc 可以在 nix-shell 中轻松找到它。

当使用-v3 运行时,它似乎试图链接到-llibmnl。但正确的链接应该是-lmnl。这似乎很成问题,有没有办法告诉 cabal 与标志 -lmnl 链接,而不是 -llibmnl

我发现,如果我编辑 Cabal 文件并将 extra-libraries 更改为指向 mnl 而不是 libmnl,那么它会通过更改 Cabal 尝试链接的方式来工作。但是,cabal2nix 然后在使用package.yaml 时会生成libmnl,这是来自 Nix 的正确包属性。看来extra-libraries 应该是mnlcabal.nix 应该是libmnl

【问题讨论】:

    标签: haskell cabal nix


    【解决方案1】:

    基本上extra-libraries 需要使用mnl 而不是libmnl。那么在使用cabal2nix时,需要将libmnl包映射到mnl属性。上游 cabal2nix 将 mnl 映射到 libmnl 提交解决了这个问题:https://github.com/NixOS/cabal2nix/issues/413#event-2257811946

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-04
      • 1970-01-01
      • 1970-01-01
      • 2016-02-05
      • 2018-10-22
      • 1970-01-01
      • 2013-10-15
      • 2014-11-12
      相关资源
      最近更新 更多