Drathier
Drathier

Reputation: 14539

How to call 3rd party Erlang module from Elixir?

I have an Elixir project that uses mix. I already use some built-in erlang modules, but now I need to use a third party module I found on Github.

How do I import, build and call a third party Erlang module from Elixir?

EDIT: The module I am interested in right now is located at https://github.com/aggelgian/erlang-algorithms , specifically, the edmonds_karp module.

Upvotes: 2

Views: 1454

Answers (1)

Harrison Lucas
Harrison Lucas

Reputation: 2961

Adding third-party erlang packages is quite easy in elixir. If the package isn't on Hex.pm, then you can just use the github url. E.g. in mix.exs:

defp deps do
  [
    {:erlang_algorithms, github: 'aggelgian/erlang-algorithms'},
  ]
end

Then you can just run mix deps.get

However in your case this will fail because the package doesn't have an app file. To fix this change the above to be:

  defp deps do
    [
      {:erlang_algorithms, github: 'aggelgian/erlang-algorithms', app: false},
    ]
  end

Then again run mix deps.get.

Now you can access the erlang modules available in the package:

E.g.

:dfs.run(arg1, arg2)

Upvotes: 8

Related Questions