Can elixir or erlang programs be compiled to a standalone binary?

帅比萌擦擦* 提交于 2019-12-04 08:10:00

问题


It sees that elixir has a tool called elixirc and erlang has a tool called erlc to compile modules for use. It says immediately after this that you can then run code with the elixir command line tool.

Is there a way to compile a binary executable with elixir or erlang? (one which I can chmod +x binary_name and then run from the same directory with ./binary_name)


回答1:


Escripts support that to some extent but you still need Erlang installed in your machine. See this answer for more information: Elixir or Hex portable package format?




回答2:


You can use tools like rebar to generate a release that also contains the erts, which makes it possible to run said release on a machine where erlang is not installed. But the erts included corresponds to the operating system on which the release was built, i.e. windows binaries if built on windows.




回答3:


Make sure you checkout Distillery. It does what you need, without having to deal with Rebar.

Add this to your mix.exs file's dependencies then run mix release.

defp deps do
  [{:distillery, "~> 0.9"}]
end

Their documentation is great:

  • Home - Distillery Documentation



回答4:


You can use Elixir's built-in releases as of Elixir 1.9. It is a lightweight alternative to Distillery.

Caveats: It will not create anything remotely like Go does with a single binary executable that you can run almost anywhere. Also your target will have to match the CPU architecture and OS.

To build a release run:

mix release

Read more here: https://hexdocs.pm/mix/Mix.Tasks.Release.html



来源:https://stackoverflow.com/questions/31861544/can-elixir-or-erlang-programs-be-compiled-to-a-standalone-binary

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!