Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load an Erlang module within a Elixir/mix project?

Tags:

erlang

elixir

I have an Elixir project managed by mix. When started with iex -S mix all Elixir modules within my lib folder get loaded. An Erlang module in an .erl file within the lib folder doesn't.

I'd like to know either a) how do I load an Erlang module explicitly from my Elixir code or b) what do I have to do to have mix autoload the Erlang module, too. (Preferably both ;) )

like image 305
Niko Avatar asked Mar 06 '23 00:03

Niko


1 Answers

Erlang modules that get compiled will get included automatically. If your local erlang module is in the lib/ folder though the problem may be that its not getting compiled.

The mix task that handles compiling erlang modules (mix compile.erlang) assumes the default path where the erlang modules are included is in a src/ directory.

If you'd prefer to place it somewhere else, you can adjust the configuration via the :erlc_paths parameter, in your project config in mix.exs. A bare bones example would look like:

def project do
  [
    app: :test,
    version: "0.1.0",
    elixir: "~> 1.6",
    erlc_paths: ["lib"],
    start_permanent: Mix.env() == :prod,
    deps: deps()
  ]
end
like image 80
The Brofessor Avatar answered Mar 12 '23 02:03

The Brofessor