4
votes

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 ;) )

1
Why did you put erlang module into .ex file in the first place? Put in into .erl file.Aleksei Matiushkin
Sorry. It is an .erl file. I corrected the question. Thanks for the hint.Niko

1 Answers

7
votes

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