Where to place my erlang myerlib.erl library module in the elixir tree directory to call from elixir modules

I have a module myerlib / src / myerlib.erl erlang and I need to call its functions from Elixir modules. Too call the functions of the myerlib module from elixir code, I could write: myerlib.function (.....), but

If I put the myerlib subdirectory in the deps / elixir directory and use mix.exs:

def deps do [ {:myerlib, path: "deps/myerlib"} # ... ] end 

then when I do iex -S mix , I get this error:

*** (Mix): path parameter can only be used with mixing projects, invalid path dependency for: myerlib

+5
source share
2 answers

If you have a src directory with .erl files in it, then they will be compiled when you run mix.compile (either using mix compile or implicitly with something like iex -S mix ).

This can be seen in mix compile.erlang . This may be the default src path, but this can be changed by changing the erlc_paths parameter in your mix.exs file.

 def project do [app: :my_app, version: "0.0.1", elixir: "~> 1.0", erlc_paths: ["foo"], # ADD THIS OPTION build_embedded: Mix.env == :prod, start_permanent: Mix.env == :prod, deps: deps] end 
+7
source

I found this solution this morning:

https://github.com/alco/erlang-mix-project

Why does this link answer a substantive question:

1.- we have the main elixir project under rssutil /

2.- we have the library myerlib.erl erlang, which we should use from the elixir code that we have in rssutil / lib /

3.- One solution is to create rssutil / src / and copy myerlib.erl and compile as the first answer tell us earlier.

4.- But we want to manage our erlang libraries, such as deps elixir proyects. To do this, we need the elixir to consider the myerlib erlang library as an elixir project.

5.- then add myerlib as dep in rssutil / mix.exs

 defp deps do [.......... {:myerlib, path:deps/myerlib"} ] end 

6.- We need to create rssutil / deps / myliberl / with the following mix.exs file:

 defmodule Myerlib.Mixfile do use Mix.Project def project do [app: :myerlib, version: "0.0.1", language: :erlang, deps: deps] end def application do [applications: [], mod: {:myerlib, []}] end defp deps do [ {:mix_erlang_tasks, "0.1.0"}, ] end end 

Note that the language is now erlang, and that we need as myerlib dep /

mix_erlang_tasks

7.- also create rssutil / deps / myerlib / src / myerlib.erl with your "old" erlang code

8.- In the rssutil / deps / myerlib / directory, where you have the latest mix.exs file, write

 $ mix deps.get $ mix compile 

9.- Go to the rssutil / directory as well

 $ mix deps.get $ iex -S mix 

10.- And in the end, you can call erlang s functions in myerlib.erl with:

iex>: myerlib.any_function_you_know_to_have_here (...)

what all.

In any case, thank you very much.

+1
source

All Articles