views:

749

answers:

3

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.

thanks

+3  A: 

May be this guide helps you.

demas
Unfortunately work on this stopped with Erlang R9.
Warren Young
+6  A: 

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.

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.

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.

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.

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.

Warren Young
I just did a quick hack at this, and it looks like you can get the Erlang runtime down to under 2 MB. All you need is a subset of the files in the erts-VERSION/bin directory underneath the directory you installed Erlang in. I got something that appears to work using only beam.smp.dll, epmd.exe, erl.exe, erl.ini, erlexec.dll, erlsrv.exe and heart.exe. Some of those appear to be optional. I'm not sure how kosher it is to ship only beam.smp.dll and not beam.dll, or vice versa; you might really need both. That takes you up to 3 MB uncompressed. Tiny, these days.
Warren Young
+1  A: 

thanks for the answers, but i meant to run this without the runtime at all. this means to convert Erlang to some low level language (like c) and than to compile it (which is much more complicated). shoving the runtime with the compiled file doesn't help me much.. :/

qwerty