在NixOS上构建时Cabal找不到外部图书馆 [英] Cabal can't find foreign library when building on NixOS

查看:111
本文介绍了在NixOS上构建时Cabal找不到外部图书馆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用cabal2nix在NixOS上构建内部Haskell项目。它包装(并因此而来)一个外部库,该库在Ubuntu上将通过 wget 设置源代码,然后运行 make&&构建。进行安装和安装ldconfig 。因此,当cabal生成程序时,显然可以找到合适的头文件(位于 / usr / local / include / ta-lib / usr / include / ta-lib )。

I am trying to build an internal Haskell project on NixOS using cabal2nix. It wraps (and thus depends on) a foreign library which on Ubuntu one would build by wgetting the source, then running make && make install && ldconfig. Thus when cabal goes to build the program, it is apparently able to find the appropriate header files (which are in /usr/local/include/ta-lib or /usr/include/ta-lib).

在Nix上,据我了解,该过程是设置.nix文件指定如何获取和构建源代码,然后Nix设置隔离的构建环境。当我这样做时,将提取并适当构建外部库。

On Nix, the process as I understand is to setup a .nix file to specify how to get and build the source, and then Nix sets up the isolated build environments. When I do this, the foreign library is fetched and built appropriately.

当Nix运行configure步骤时,看起来还不错:

When Nix runs the configure step, it looks alright:

configureFlags: --verbose --prefix=/nix/store/fwpw03bd0c2m5yb7v2wc7g6f0qj912ra-talib-0.1.0.0 --libdir=$prefix/lib/$compiler --libsubdir=$pkgid --with-gcc=gcc --package-db=/tmp/nix-build-talib-0.1.0.0.drv-0/package.conf.d --ghc-option=-optl=-Wl,-rpath=/nix/store/fwpw03bd0c2m5yb7v2wc7g6f0qj912ra-talib-0.1.0.0/lib/ghc-7.10.2/talib-0.1.0.0 --enable-split-objs --disable-library-profiling --disable-executable-profiling --enable-shared --enable-library-vanilla --enable-executable-dynamic --enable-tests --extra-include-dirs=/nix/store/gvglncjgd5yif9bc03qalmp2mrjp524n-ta-lib-0.4.0/include --extra-lib-dirs=/nix/store/gvglncjgd5yif9bc03qalmp2mrjp524n-ta-lib-0.4.0/lib

-extra-include-dirs -extra-lib-dirs 设置为Nix中的正确路径商店。但是,在构建时会抱怨

With --extra-include-dirs and --extra-lib-dirs set to the correct paths in the Nix store. However, when it goes to build it complains with,

Setup: Missing dependency on a foreign library:
* Missing C library: ta_lib

不幸的是,我不明白集团是如何确定是否存在外国图书馆的。我在这里阅读( Haskell如何解决集团错误:缺少对外部库的依赖?),cabal会尝试构建并链接一个针对所找到的每个标头组成的C程序。因此,以某种方式找不到正确的库。

Unfortunately I don't understand how cabal is determining whether the foreign library is present. I read here (Haskell how to resolve cabal error: Missing dependencies on foreign libraries?) that cabal will try to build and link a C program that consists of for each header it finds. So, somehow it is not finding the correct library.

出什么问题了?这与Ubuntu中运行ldconfig的步骤有关吗?

What is wrong? Does this have to do with the step in Ubuntu of running ldconfig?

推荐答案

问题是 ta_lib 取决于系统数学库 m ,但默认情况下未链接该库。您可以通过创建存根C程序

The problem is that ta_lib depends on the system math library m, but that library isn't linked by default. You can check that by creating a stub C program

echo "int main() { return 0; }" >test.c

并尝试将其与 ta_lib 链接:

$ nix-shell -p ta_lib --run "gcc test.c -lta_lib"
/nix/store/ghinzmxfm2s41nz8y873jlywwmcbw38l-ta-lib-0.4.0/lib/libta_lib.so: undefined reference to `sinh'
/nix/store/ghinzmxfm2s41nz8y873jlywwmcbw38l-ta-lib-0.4.0/lib/libta_lib.so: undefined reference to `sincos'
[...]
collect2: error: ld returned 1 exit status

现在,当Cabal尝试确定该库是否可用时,它将尝试将其链接到存根测试程序,但是由于所有这些未定义的符号,该尝试将失败。因此,Cabal抱怨无法链接库(即使已正确配置和设置了其路径)。

Now, when Cabal tries to determine whether the library is available, it will attempt to link it to a stub test program, but that attempt will fail because of all those undefined symbol. Hence, Cabal complains that the library cannot be linked (even though its paths are configured and set-up correctly).

要解决该问题,请添加 m 库添加到项目的Cabal文件中的 extra-libraries 属性,例如:

To remedy that issue, add the m library to the extra-libraries attribute in your project's Cabal file, like so:

extra-libraries: ta_lib, m

应该使Cabal配置阶段成功。

That should make the Cabal configure phase succeed.

这篇关于在NixOS上构建时Cabal找不到外部图书馆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆