Search code examples
compilationerlangelixirelixir-mix

LIbrary paths for mix compile process


After moving from brew to asdf version control tool for Elixir and Erlang I still cant compile my old projects: in the compile process it tries to refer to non-existent Brew's Cellar lib files:

MacBook-Pro% mix test
==> gettext
Compiling 1 file (.erl)
/usr/local/Cellar/erlang/21.3.2/lib/erlang/lib/parsetools-2.1.8/include/yeccpre.hrl:59: illegal pattern
/usr/local/Cellar/erlang/21.3.2/lib/erlang/lib/parsetools-2.1.8/include/yeccpre.hrl:60: variable 'Error' is unbound
/usr/local/Cellar/erlang/21.3.2/lib/erlang/lib/parsetools-2.1.8/include/yeccpre.hrl:60: variable 'Stacktrace' is unbound
/usr/local/Cellar/erlang/21.3.2/lib/erlang/lib/parsetools-2.1.8/include/yeccpre.hrl:63: variable 'Stacktrace' unsafe in 'try' (line 60)
/usr/local/Cellar/erlang/21.3.2/lib/erlang/lib/parsetools-2.1.8/include/yeccpre.hrl:64: variable 'Error' unsafe in 'try' (line 60)
/usr/local/Cellar/erlang/21.3.2/lib/erlang/lib/parsetools-2.1.8/include/yeccpre.hrl:64: variable 'Stacktrace' unsafe in 'try' (line 60)
could not compile dependency :gettext, "mix compile" failed. You can recompile this dependency with "mix deps.compile gettext", update it with "mix deps.update gettext" or clean it with "mix deps.clean gettext"

even though there is no any /usr/local/Cellar/erlang folder

where does the mix take the paths to external erlang libs and how to change that to use the asdf's bundles?


Solution

  • Erlang, and also Elixir use binaries and libs from your $PATH environment variable as described here: https://elixir-lang.org/install.html#installing-erlang

    asdf usually is loaded at the end of your $PATH, which means that if you still have Erlang and Elixir installed via brew it's gonna be loaded first. That said, please double check if any other Erlang version is installed via brew. You can uninstall all versions with the command brew uninstall erlang --force

    Also set the local Erlang and Elixir versions in the root dir of your project with the commands:

    asdf local erlang 21.3.2
    asdf local elixir 1.8.1-otp-21
    

    Change versions according to your environment.

    And finally check if asdf is loading the correct version with the command asdf current. It should display something like:

    elixir         1.8.1-otp-21 (set by /path/to/project/.tool-versions)
    erlang         21.3.2   (set by /path/to/project/.tool-versions)
    

    As a last resort, check out https://asdf-vm.com/#/core-manage-asdf-vm?id=having-issues.