在cabal中使用Extra-lib-dirs的相对路径 [英] Use relative paths for extra-lib-dirs on cabal
问题描述
我有一个带有Makefile的C库"myboo".我想包装这个库.我不想将其安装到/usr/local,因为"myboo"不是主要模块.另外,建议不要将"myboo"构建为动态库但作为静态库.
我通过自定义Setup.py来构建"myboo";
main :: IO()main = defaultMainWithHooks simpleUserHooks {preBuild = \ a b->makeLib a b>>preBuild simpleUserHooks a b}makeLib :: Args->BuildFlags->IO()makeLib _标志=做let verbosity = fromFlag $ buildVerbosity标志cflags<-lookupEnv"CFLAGS">> = return.也许" IDsetEnv"CFLAGS" $"-fPIC" ++('':cflags)rawSystemExit详细信息"env" ["make","--directory = myboo","libmyboo.a"]
然后我将myboo.cabal安排为将我的haskell代码链接到C库;
库暴露的模块:MyBoo构建依赖关系:基本> = 4.7&&< 4.8hs-source-dirs:src默认语言:Haskell2010包含目录:myboo额外的图书馆:mybooExtra-lib-dirs:myboo
当我运行"cabal build"时,收到以下消息.
myboo-0.1.0.0:library-dirs:myboo是一个没有意义的相对路径(因为没有相对关系).您可以相对于使用$ {pkgroot}打包数据库本身.(使用--force覆盖)
如果我写"extra-lib-dirs:/absolute/path/to/working/dir/myboo",看来它运行良好.但这不是一个好方法,因为/absolute/...只是一个工作目录.
如何解决以上错误消息?我的环境在这里;
%ghc --versionGlorious Glasgow Haskell编译系统,版本7.8.2%cabal --versioncabal安装版本1.20.0.2使用Cabal库的1.20.0.0版本%cat/etc/lsb-发行版DISTRIB_ID = UbuntuDISTRIB_RELEASE = 14.04DISTRIB_CODENAME =可信任DISTRIB_DESCRIPTION ="Ubuntu 14.04 LTS"
您可以编写自己的Setup.hs和设置 Distribution.Simple.confHook
.在挂钩函数中,修改 Distribution.PackageDescription.extraLibDirs
以包括目录.
请注意,您还需要在阴谋文件中将 build-type
更改为 Custom
.
这里是指向 Setup.hs 的链接,在其中完成了我写的内容./p>
I have a C library "myboo" which has Makefile. I want to make a wrapper of this library. I don't want to install it into /usr/local since "myboo" is not a major module. Additionally it is recommended that I build "myboo" not as a dynamic library but as a static library.
I make custom Setup.py to build "myboo";
main :: IO ()
main = defaultMainWithHooks simpleUserHooks {
preBuild = \a b -> makeLib a b >> preBuild simpleUserHooks a b
}
makeLib :: Args -> BuildFlags -> IO ()
makeLib _ flags = do
let verbosity = fromFlag $ buildVerbosity flags
cflags <- lookupEnv "CFLAGS" >>= return . maybe "" id
setEnv "CFLAGS" $ "-fPIC" ++ (' ' : cflags)
rawSystemExit verbosity "env" ["make", "--directory=myboo", "libmyboo.a"]
And I arrange myboo.cabal to link my haskell codes to C library;
library
exposed-modules: MyBoo
build-depends: base >=4.7 && <4.8
hs-source-dirs: src
default-language: Haskell2010
include-dirs: myboo
extra-libraries: myboo
extra-lib-dirs: myboo
When I run "cabal build", I got following messages.
myboo-0.1.0.0: library-dirs: myboo is a relative path which makes no sense (as
there is nothing for it to be relative to). You can make paths relative to the
package database itself by using ${pkgroot}. (use --force to override)
If I write "extra-lib-dirs: /absolute/path/to/working/dir/myboo", it seems that it works well. But it's not good way because /absolute/... is just a working directory.
How should I fix above error messages? My environment is here;
% ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.8.2
% cabal --version
cabal-install version 1.20.0.2
using version 1.20.0.0 of the Cabal library
% cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04 LTS"
You can write your own Setup.hs and setup Distribution.Simple.confHook
. In your hook function, modify Distribution.PackageDescription.extraLibDirs
to include the directory.
Note that you also need to change the build-type
to Custom
in your cabal file.
Here is a link to Setup.hs in which I did what I wrote.
这篇关于在cabal中使用Extra-lib-dirs的相对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!