使用 nix-shell 通过 cabal 查找外国图书馆
Finding foreign library with cabal using nix-shell
我有类似的问题:
基本上我使用 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.
此外 运行ning gcc -c test.c -lmnl
在 nix-shell
内的这个文件上工作:
#include <libmnl/libmnl.h>
int main() { return 0; }
那么为什么 cabal 找不到 libmnl
但 gcc
可以很容易地在 nix-shell
.
中找到它
当 运行 -v3
它似乎试图 link 到 -llibmnl
。但正确的 linking 应该是 -lmnl
。这看起来很有问题,有没有办法告诉 cabal 使用标志 -lmnl
,而不是 -llibmnl
?
我发现,如果我编辑 Cabal 文件并将 extra-libraries
更改为指向 mnl
而不是 libmnl
,它就会通过更改 Cabal 尝试 [=] 的方式来工作57=]。然而,cabal2nix
然后在采用 package.yaml
时生成 libmnl
,这是来自 Nix 的正确包属性。看起来 extra-libraries
应该是 mnl
而 cabal.nix
应该是 libmnl
.
基本上 extra-libraries
需要使用 mnl
而不是 libmnl
。那么在使用cabal2nix
时,需要将libmnl
包映射到mnl
属性。这已通过上游 cabal2nix 将 mnl 映射到 libmnl 提交解决:https://github.com/NixOS/cabal2nix/issues/413#event-2257811946
我有类似的问题:
基本上我使用 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.
此外 运行ning gcc -c test.c -lmnl
在 nix-shell
内的这个文件上工作:
#include <libmnl/libmnl.h>
int main() { return 0; }
那么为什么 cabal 找不到 libmnl
但 gcc
可以很容易地在 nix-shell
.
当 运行 -v3
它似乎试图 link 到 -llibmnl
。但正确的 linking 应该是 -lmnl
。这看起来很有问题,有没有办法告诉 cabal 使用标志 -lmnl
,而不是 -llibmnl
?
我发现,如果我编辑 Cabal 文件并将 extra-libraries
更改为指向 mnl
而不是 libmnl
,它就会通过更改 Cabal 尝试 [=] 的方式来工作57=]。然而,cabal2nix
然后在采用 package.yaml
时生成 libmnl
,这是来自 Nix 的正确包属性。看起来 extra-libraries
应该是 mnl
而 cabal.nix
应该是 libmnl
.
基本上 extra-libraries
需要使用 mnl
而不是 libmnl
。那么在使用cabal2nix
时,需要将libmnl
包映射到mnl
属性。这已通过上游 cabal2nix 将 mnl 映射到 libmnl 提交解决:https://github.com/NixOS/cabal2nix/issues/413#event-2257811946