当交叉编译haskell代码时,如何安装依赖项?

我已经成功地创建了一个ghc交叉编译器,它允许我从我的x64 linux机器中编译armv6h(我​​的case中的raspBerry pi)的haskell代码.
我已经成功地在树莓上运行了一个你好世界的节目.

不,我想建立我的真正的应用程序,它有很多依赖于其他haskell模块.
当我为x64编译时,我只是这样做

cabal install dependenciy1 depenency2 ...

我知道我可以使自己的程序一个cabal项目自动化这一步.但这不是重点.

当我尝试使用交叉编译器

arm-unkNown-linux-gnueabi-ghc --make myapp.hs

它告诉我关于它找不到的模块.当然,他们没有安装!

我读了https://ghc.haskell.org/trac/ghc/wiki/Building/CrossCompiling
根据我试过

cabal --with-ghc=arm-unkNown-linux-gnueabi-ghc --with-ghc-pkg=arm-unkNown-linux-gnueabi-ghc-pkg --with-ld=arm-unkNown-linux-gnueabi-ld install random

随机是我在这里安装的依赖.我收到以下错误

Resolving dependencies...
Configuring random-1.0.1.3...
Failed to install random-1.0.1.3
Last 10 lines of the build log ( /home/daniel/.cabal/logs/random-1.0.1.3.log ):
/home/daniel/.cabal/setup-exe-cache/setup-Cabal-1.18.1.3-arm-linux-ghc-7.8.3.20140804: /home/daniel/.cabal/setup-exe-cache/setup-Cabal-1.18.1.3-arm-linux-ghc-7.8.3.20140804:      cannot execute binary file
cabal: Error: some packages Failed to install:
random-1.0.1.3 Failed during the configure step. The exception was:
ExitFailure 126

当我做

file /home/daniel/.cabal/setup-exe-cache/setup-Cabal-1.18.1.3-arm-linux-ghc-7.8.3.20140804

我得到

/home/daniel/.cabal/setup-exe-cache/setup-Cabal-1.18.1.3-arm-linux-ghc-7.8.3.20140804: ELF 32-bit LSB executable,ARM,EABI5 version 1 (SYSV),dynamically linked (uses shared libs),for GNU/Linux 3.10.2,not stripped

难怪它无法执行.它是为arm编译的.

在这里遗漏了什么吗?
我的目标是拉扯所有依赖,然后创建一个静态链接的应用程序,我可以在我的树莓上部署.

要了解这个错误,你需要知道cabal如何在内部安装.实质上,它将执行以下步骤:

>下载并解压缩源代码
> Compile Setup.hs(此文件用于定制构建系统,例如,您可以在配置阶段实现一些钩子来运行其他的haskell代码).
>运行setup configure< configure flags> &安培;&安培;设置构建&&安装安装

现在的问题是,cabal安装使用–with-ghc给出的GHC也适用于步骤2,但由该步骤生成的可执行文件必须在主机系统上运行!

解决办法是手动执行这些步骤,这意味着您有完全的控制权.首先,得到来源:

$cabal get random
Downloading random-1.0.1.3...
Unpacking to random-1.0.1.3/
$cd random-1.0.1.3

然后编译Setup.hs,使用主机ghc:

$ghc ./Setup.hs -o setup

最后,配置,构建和安装.根据@Yuras在评论中的建议,我们还添加了运行hsc2hs的-x选项:

$./setup configure ----with-ghc=arm-unkNown-linux-gnueabi-ghc --with-ghc-pkg=arm-unkNown-linux-gnueabi-ghc-pkg --with-ld=arm-unkNown-linux-gnueabi-ld --hsc2hs-options=-x
$./setup build && ./setup install

已经有一个关于这个的问题:https://github.com/haskell/cabal/issues/2085

相关文章

迭代器模式(Iterator)迭代器模式(Iterator)[Cursor]意图...
高性能IO模型浅析服务器端编程经常需要构造高性能的IO模型,...
策略模式(Strategy)策略模式(Strategy)[Policy]意图:定...
访问者模式(Visitor)访问者模式(Visitor)意图:表示一个...
命令模式(Command)命令模式(Command)[Action/Transactio...
生成器模式(Builder)生成器模式(Builder)意图:将一个对...