使用nix-shell查找带有cabal的外部库

问题描述 投票:1回答:1

我有一个类似的问题: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.

gcc -c test.c -lmnl里面的这个文件上运行nix-shell

#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个回答
1
投票

基本上extra-libraries需要使用mnl而不是libmnl。然后当使用cabal2nix时,它需要将libmnl包映射到mnl属性。这是通过上游cabal2nix映射mnl到libmnl commit:https://github.com/NixOS/cabal2nix/issues/413#event-2257811946解决的

© www.soinside.com 2019 - 2024. All rights reserved.