创建一个静态Haskell Linux可执行文件 [英] Create a static Haskell Linux executable

查看:293
本文介绍了创建一个静态Haskell Linux可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常不喜欢两件事情,因为这两件事导致我非常烦恼(除了我的孩子)。我在工作中编写了一个Haskell程序,它使用像text,xml-enumerator,attoparsec-text等库。我可以正常工作在我的Windows机器上,我的Ubuntu虚拟机在工作(32位),我的Ubuntu桌面(32位)和一个运行Ubuntu(64位)的EC2实例。

我们的客户端运行的是CentOS 5.3,64位。我不能为我的生活得到这个可执行文件正常运行。我尝试使用以下方法创建静态可执行文件:

  ghc --make myprog.hs -optl-static -optl-pthread 

但是当我尝试在CentOS服务器上运行该可执行文件时,出现错误消息:

  openFile:无效参数(无效参数)

我假设这与此处描述的错误相关。我试过编译32位和64位Ubuntu,尝试过静态和共享构建,没有任何工作(尽管我偶尔会得到段错误而不是上述错误信息)。我可以尝试下载CentOS 5.3并为它创建一个虚拟机,但它需要一段时间才能下载,而且我不确定哪个版本的GHC可以工作(我尝试在他们的服务器上获得GHC 7,但是我跑了到一个libc的问题)。

在这一点上,我提出了一些可能的方法,但我想尽可能避免这些方法:




  • 用不同的语言重写(在Java中这样做的想法让我感到不安,虽然它可能是尝试Cal / OpenQuark)。

  • 也许试试一个替代编译器,如jhc。但我不太确定如何开始在jhc中安装此程序的所有依赖项;如果人们有经验并且知道text / attoparsec / etc在jhc中工作,我很乐意听到它。 所有黑客攻击:构建一个Windows可执行文件,在他们的服务器上安装wine并以此方式运行。



总的来说,这些情况是我真的希望我们有一个用于GHC的JVM后端。我想我也可以试用LambdaVM。但我很乐意听到关于在这里做什么的社区建议。 解决方案

这个简单的例子对我有用:

  $ cat A.hs 
main =打印是

$ ghc -O2 --make -static -optc-static -optl-static A.hs -fvia-C -optl -pthread

$ ldd A
不是动态可执行文件
$ .// A

(我通过.cabal使用了这个过程,在过去几年为客户提供可执行文件)。



我认为最好的选择是编写错误,并使其正常工作。 IHG也可以为此类工作提供资金,但如果您尝试运送产品,我相信GHC团队会认为这是高优先级。


It's not often two things I love so much come together to cause me so much annoyance (besides my kids). I've written a Haskell program at work that uses libraries like text, xml-enumerator, attoparsec-text, etc. I have it working properly on my Windows machine at work, my Ubuntu virtual machine at work (32-bit), my Ubuntu desktop (32-bit again) and an EC2 instance running Ubuntu (64-bit).

Our client is running CentOS 5.3, 64-bit. I can't for the life of me get this executable to run properly. I tried creating a static executable using:

ghc --make myprog.hs -optl-static -optl-pthread

But when I try to run that executable on the CentOS server, I get an error message:

openFile: invalid argument (Invalid argument)

I'm assuming this is related to the bug described here. I've tried compiling from both 32 and 64 bit Ubuntu, tried static and shared builds, nothing works (though I occasionally get segfaults instead of the above error message). I can try downloading CentOS 5.3 and creating a virtual machine for it, but it will take a while to download, and I'm not sure which version of GHC will work on it (I tried getting GHC 7 on their server, but I ran into a libc issue).

At this point, I've come up with a few possible approaches, but I'd like to avoid these if at all possible:

  • Rewrite in a different language (the thought of doing this in Java makes me queasy, though it could be a nice time to try out Cal/OpenQuark).
  • Maybe try out an alternate compiler, like jhc. But I'm not quite certain how to get started installing all the dependencies for this program in jhc; if people have experience and know that text/attoparsec/etc work in jhc, I'd love to hear it.
  • Hack of all hacks: build a Windows executable, install wine on their server and run it that way.

As a total aside, these are the situations where I really wish we had a JVM backend for GHC. I suppose I could try out LambdaVM as well. But I'd love to hear community advice on what to do here.

解决方案

This simple example "works for me":

$ cat A.hs
main = print "yes"

$ ghc -O2 --make -static -optc-static -optl-static A.hs -fvia-C -optl-pthread

$ ldd A
    not a dynamic executable
$ ./A
"yes"

(and I've used this process, via .cabal, to ship executables for clients in the past couple of years).

I think the best bet is to file bugs, and get this working. The IHG can also fund work like this, but I'm fairly sure the GHC team would consider this a high priority, if you're trying to ship products.

这篇关于创建一个静态Haskell Linux可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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