haskell - 使用 nix-shell 查找带有 cabal 的外国图书馆
问题描述
我有一个类似的问题: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 找不到libmnl
但gcc
可以在nix-shell
.
使用它运行-v3
时似乎尝试链接到-llibmnl
. 但正确的链接应该是-lmnl
. 这似乎很成问题,有没有办法告诉 cabal 与 flag 链接-lmnl
,不是-llibmnl
吗?
我发现,如果我编辑 Cabal 文件并将其更改extra-libraries
为指向mnl
而不是libmnl
,那么它会通过更改 Cabal 尝试链接的方式来工作。但是,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
推荐阅读
- reactjs - 如何使用 Material Ui 处理不同布局的网格
- python - 为什么我会看到多个 spark 安装目录?
- typo3 - TYPO3 CONTENT 选择将参数传递给 USER/USER_INT
- java - 迭代器没有给我所有的整数,还是我在做一些愚蠢的事情?
- web-scraping - 如何逆向工程 POST 请求的正文生成
- android - Charles Proxy 证书已安装在设备上,但呼叫被阻止 Android
- javascript - 我如何过滤对象数组中的数组值
- c - C:无法用有符号整数表示负值
- python - 如何从 SharePoint Online 下载列表数据到 csv(最好)或 json 文件?
- python - 使用递归时如何避免内存错误?(斐波那契数列)