如何指定.cabal中的外部C库的依赖关系? [英] How to specify dependency on external C library in .cabal?
问题描述
我在Hackage上维护一个带FFI绑定的库。所以我的Haskell库依赖于相应的C库及其头文件。现在我在 .cabal
文件中指定外部依赖关系,如下所示:
PkgConfig - 取决于:
libfoo> = 1.2
Linux操作系统。不过,我有一位图书馆用户报告说,在Windows上安装 pkg-config
非常麻烦,而且他更喜欢
包含:
foo.h
Extra-libraries:
foo
我希望我的库尽可能容易构建,并且不想强制不严格要求的构建依赖关系。不过,我看到 Cabal手册建议使用 PkgConfig-Depends
。
我的问题:
.cabal
文件,这样它可以与 pkg-config
并且没有?
pkg-config
(我没有Windows机器可以立即检查)?
$ / $> $因为pkg-config知道在哪里可以找到包含和库文件,这些文件可能位于某些系统的非标准位置,所以最好使用pkg-config方法。
您可以编写.cabal文件以使用这两种方法。如此处所示,使用标志具有的优点是,如果默认值失败,Cabal将自动尝试另一个标志值。 (下面的例子未经测试)
标记UsePkgConfig
描述:使用pkg-config检查库依赖性
默认值:True
可执行文件
if flag(UsePkgConfig)
PkgConfig-Depends:libfoo> = 1.2
else
包含:foo。 h
Extra-libraries:foo
I maintain a library with FFI bindings on Hackage. So my Haskell library depends on the corresponding C library and its header files. Now I specify the external dependency in the .cabal
file like this:
PkgConfig-Depends:
libfoo >= 1.2
And it works well for me in Linux. However, I have a user of the library who reports, that installing pkg-config
on Windows is rather cumbersome, and instead he prefers
Includes:
foo.h
Extra-libraries:
foo
I'd like my library to be as easy to build as possible, and don't want to force build dependencies which are not strictly required. However, I see that Cabal manual suggests to use PkgConfig-Depends
.
My questions:
- Which way I should prefer for cross-platform packages?
- Is it possible to write a
.cabal
file in such a way, that it can work withpkg-config
and without? - And, by the way, is
pkg-config
included in the Haskell platform (I don't have a Windows machine to check right now)?
The pkg-config method is preferable because pkg-config knows where to find include and library files, which may be in nonstandard locations on some systems.
You can write the .cabal file to use both methods. Using a flag, as shown here, has the advantage that Cabal will automatically try the other flag value if the default fails. (Below example is not tested)
Flag UsePkgConfig
Description: Use pkg-config to check for library dependences
Default: True
Executable hax
if flag(UsePkgConfig)
PkgConfig-Depends: libfoo >= 1.2
else
Includes: foo.h
Extra-libraries: foo
这篇关于如何指定.cabal中的外部C库的依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!