创建静态 Haskell Linux 可执行文件

发布于 2024-11-06 05:51:15 字数 1125 浏览 4 评论 0原文

我如此喜爱的两件事很少同时出现,给我带来如此多的烦恼(除了我的孩子)。我在工作中编写了一个 Haskell 程序,它使用文本、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: invalid argument (Invalid argument)

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

此时,我已经提出了一些可能的方法,但如果可能的话,我想避免这些:

  • 用不同的语言重写(用 Java 执行此操作的想法让我感到不安,尽管这可能是尝试 Cal/OpenQuark 的好时机)。
  • 也许尝试其他编译器,例如 jhc。但我不太确定如何开始在 jhc 中安装该程序的所有依赖项;如果人们有经验并且知道 text/attoparsec/etc 在 jhc 中工作,我很想听听。
  • Hack of all hacks:构建一个 Windows 可执行文件,在他们的服务器上安装 wine 并以这种方式运行它。

总而言之,在这些情况下,我真的希望我们有一个适用于 GHC 的 JVM 后端。我想我也可以尝试一下 LambdaVM。但我很想听听社区关于在这里做什么的建议。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

飘然心甜 2024-11-13 05:51:15

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

$ 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"

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

我认为最好的办法是提交错误并让其正常工作。 IHG 也可以资助此类工作,但我相当确定,如果您想运送产品,GHC 团队会将此视为重中之重。

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.

叶落知秋 2024-11-13 05:51:15

它与CentOS中旧的glibc库有关。您必须使用与 CentOS 上安装的相同版本的 glibc 进行编译。

我有完全相同的问题。在 arch(或 ubuntu)上编译的 Haskell 可执行文件无法在 CentOS 上运行。就我而言,我很幸运,因为我们的管理员刚刚删除了 CentOS 并为应用程序服务器安装了 Arch。

It is related to the old glibc library in CentOS. You have to compile with the same version of glibc as installed on CentOS.

I had exactly the same problem. Haskell executable compiled on arch (or ubuntu) won't run on CentOS. In my case though i was lucky, because our admin just removed CentOS and installed Arch for application server.

不一样的天空 2024-11-13 05:51:15

我发现了问题所在。看来 Biohaskell 页面的链接是准确的:这是加载 iconv 时出现的问题。调用 openFile 时会发生这种情况,但调用 openBinaryFile不会。由于 xml-enumerator 使用后者,所以它工作得很好。将其余代码切换为使用 openBinaryFile (通过 Data.Enumerator.Binary.enumFile)使一切正常工作。

对于我的用例来说,这是一个很好的解决方法,但错误仍然存​​在。

I found out the problem. It seems that the link to the Biohaskell page is accurate: this is a problem loading iconv. This occurs when calling openFile, but not when calling openBinaryFile. Since xml-enumerator uses the latter, it worked just fine. Switching over the rest of the code to use openBinaryFile instead (via Data.Enumerator.Binary.enumFile) got everything to work.

This is a good workaround for my use case, but the bug still exists.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文