Erlang 编译 - Erlang 作为独立的可执行文件 [英] Erlang compilation - Erlang as stand alone executeable

查看:14
本文介绍了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 文件复制到一个目录中.例如,您可以将这部分作为程序的 Makefile.

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 FilesMyProgram 并创建一个开始菜单中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 FilesMyProgram 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天全站免登陆