Erlang编译 - Erlang独立可执行 [英] Erlang compilation - Erlang as stand alone executeable

查看:203
本文介绍了Erlang编译 - Erlang独立可执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法编译Erlang成为一个独立的可执行文件?
这意味着,以不带Erlang运行时的exe运行它。

is there a way to compile Erlang to be a stand-alone executable? this means, to run it as an exe without the Erlang runtime.

推荐答案

在单个EXE中,你不会离开有Erlang运行时。像Erlang这样的动态语言不能真正地编译成原生x86代码,例如,由于它们的性质。

While it's possible to wrap everything up in a single EXE, you're not going to get away from having an Erlang runtime. Dynamic languages like Erlang can't really be compiled to native x86 code, for instance, due to their nature. There has to be an interpreter in there somewhere.

有可能想出一个将解释器和所有BEAM文件捆绑到一个EXE中的方案,点击并直接运行,但这可能比你想要的更多的工作。我以前看过它,但很少有很好的理由这样做,所以我不打算详细了解这里的技巧。

It's possible to come up with a scheme that bundles the interpreter and all the BEAM files into a single EXE you can double-click and run directly, but that's probably more work than you were wanting to go to. I've seen it done before, but there's rarely a good reason to do it, so I won't bother going into detail on the techniques here.

相反,我建议你使用他们用于Python的py2exe和py2app程序分别创建Windows和Mac OS X可执行文件相同的技术。这些程序将程序的主模块加载到Python解释器中,使用语言的内置反射机制找出需要使用的其他模块,然后将所有这些编译的模块与一个语言解释器和一个小的封装程序使用解释器启动程序的主模块。然后,包含这些文件的目录是一个独立的环境,具有运行程序所需的一切。 Erlang的唯一区别是python.exe成为erl.exe,* .pyc成为* .beam。基本思想是一样的。

Instead, I suggest you use the same technique they use for Python's py2exe and py2app programs for creating Windows and Mac OS X executables, respectively. These programs load the program's main module up into a Python interpreter, figure out which other modules it needs using the language's built-in reflection mechanisms, then write out all those compiled modules along with a copy of the language interpreter and a small wrapper program that launches the program's main module with the interpreter. The directory containing those files is then a stand-alone environment, having everything needed to run the program. The only difference in the Erlang case is that python.exe becomes erl.exe, and *.pyc becomes *.beam. The basic idea is still the same.

如果你不需要使用任何任意的Erlang程序,你可以简化它,但只有你的。在这种情况下,您只需将Erlang解释器和组成程序的所有.beam文件复制到一个目录中。例如

You can simplify this if you don't need it to work with any arbitrary Erlang program, but only yours. In that case, you just copy the Erlang interpreter and all the .beam files that make up your program into a single directory. You can make this part of your program's Makefile, for instance.

然后,您可以使用您最喜欢的setup.exe或MSI创建方法创建一个可分发的包来安装此集合的文件到最终用户系统上的 c:\Program Files \MyProgram 中,并在其开始菜单中为erl mainmodule.beam创建一个快捷方式。最终用户不关心作为程序的一部分,他们也得到一个Erlang的副本。这是一个实现细节。

You can then use your favorite setup.exe or MSI creation method for creating a distributable package that installs this collection of files into c:\Program Files\MyProgram on the end user's system and creates a shortcut for "erl mainmodule.beam" in their Start menu. The end user doesn't care that as part of the program they also get a copy of Erlang. That's an implementation detail.

这篇关于Erlang编译 - Erlang独立可执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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