如何在交叉编译haskell代码时安装依赖关系? [英] How do I install dependencies when cross compiling haskell code?

查看:211
本文介绍了如何在交叉编译haskell代码时安装依赖关系?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经成功创建了一个ghc交叉编译器,它允许我从我的x64 linux机器上编译armv6h(在我的例子中是树莓派)的haskell代码。
我已经在树莓上成功运行了hello world程序。



不,我想构建真正的应用程序,它对其他haskell模块。
当我为x64编译时,我只是简单地做
$ b $ pre code $ cab $ install dependenciy1 depenency2 ...

我知道我可以将自己的程序设计为cabal-project这一步的自动化。但这不是重点。



当我尝试使用交叉编译器时

  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  - 随机-Id = arm-unknown-linux-gnueabi -ld install随机

试图在这里安装。我得到以下错误:

 解决依赖关系... 
配置random-1.0.1.3 ...
无法安装random-1.0.1.3
构建日志的最后10行(/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:无法执行二进制文件
cabal:错误:某些软件包未能安装:
random-1.0.1.3在配置步骤中失败。例外情况是:
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位LSB可执行文件,ARM,EABI5版本1(SYSV) ,动态链接(使用共享库),为GNU / Linux 3.10.2,没有剥离

怪不得它不能执行它。它是为arm编译的。



我在这里错过了什么吗?
我的目标是引入所有的依赖关系,然后创建一个静态链接的应用程序,我可以将其部署到我的树莓上。

为了理解这个错误,你需要知道 cabal install 如何在内部工作。本质上,它将执行以下步骤:
$ b $ ol

  • 下载并解压缩源代码
  • 编译 Setup.hs (该文件用于构建系统的自定义,例如,您可以实现一些钩子以在 configure中运行额外的haskell代码

  • 运行 setup configure< configure flags> &安培;&安培;设置生成&&安装程序安装

  • 现在的问题是 cabal install 使用由 - with-ghc 给出的GHC,但该步骤产生的可执行文件必须在主机系统上运行!

    解决方法是手动执行这些步骤,这意味着您可以完全控制。首先,获取源代码:

      $ cabal get random 
    正在下载random-1.0.1.3 ...
    拆包到random-1.0.1.3 /
    $ cd random-1.0.1.3

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

      $ ghc ./Setup.hs -o setup 

    最后,configure,build并安装。正如@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


    I've successfully created a ghc cross compiler, that allows me to compile haskell code for armv6h (raspberry pi in my case) from my x64 linux machine. I've successfully run a hello world program on the raspberry.

    No I want to build my real app, which has a lot of dependencies on other haskell modules. When I compile for x64 I simply do

    cabal install dependenciy1 depenency2 ...
    

    I know I could make my own programm a cabal-project an automate this step. But that's not the point here.

    When I try to use the cross-compiler

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

    It tells me about modules it could not find. Of course, they are not installed!

    I read https://ghc.haskell.org/trac/ghc/wiki/Building/CrossCompiling and according to that I tried

    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
    

    random is the depenency I'm trying to install here. I get the following error:

    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
    

    When I do

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

    I get

    /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
    

    No wonder it can't execute it. It's compiled for arm.

    Am I missing something here? My goal is to pull in all dependencies, then create a statically linked app that I can deploy on my raspberry.

    解决方案

    To understand this error, you need to know how cabal install works internally. In essence, it will perform the following steps:

    1. Download and unpack the source code
    2. Compile Setup.hs (this file is used for customization of the build system, for example, you can implement some hooks to run additional haskell code in the configure phase).
    3. Run setup configure <configure flags> && setup build && setup install

    The problem is now that cabal install uses the GHC given by --with-ghc also for step 2, but the executable produced by that step must run on the host system!

    A workaround is to do the steps manually, which means you have full control. First, get the source:

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

    Then, compile Setup.hs, using the host ghc:

    $ ghc ./Setup.hs -o setup
    

    And finally, configure, build and install. As suggested by @Yuras in a comment, we also add the -x option for running hsc2hs:

    $ ./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
    

    There is already a cabal issue about this: https://github.com/haskell/cabal/issues/2085

    这篇关于如何在交叉编译haskell代码时安装依赖关系?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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