Kernael
Kernael

Reputation: 3280

Erlang package failing to load

I'm trying to use an Erlang package (this one : https://github.com/komone/qrcode) inside my Phoenix project, so I'm simply trying to get it from my mix file :

  defp deps do
    [{:phoenix, "~> 1.3.0-rc"},
     {:phoenix_pubsub, "~> 1.0"},
     {:phoenix_ecto, "~> 3.2"},
     {:postgrex, ">= 0.0.0"},
     {:gettext, "~> 0.11"},
     {:cowboy, "~> 1.0"},
     {:comeonin, "~> 3.0"},
     {:uuid, "~> 1.1"},
     {:timex, "~> 3.1"},
     {:timex_ecto, "~> 3.1"},
     {:porcelain, "~> 2.0"},
     {:qrcode, git: "https://github.com/komone/qrcode"}, # <--
     {:credo, "~> 0.7", only: [:dev, :test]}]
  end

I had to manually erl -make inside the fetched directory to make it compile, but at phoenix startup I get the following error :

** (Mix) Could not start application qrcode: exited in: :qrcode.start(:normal, [])
    ** (EXIT) an exception was raised:
        ** (UndefinedFunctionError) function :qrcode.start/2 is undefined or private
            (qrcode) :qrcode.start(:normal, [])
            (kernel) application_master.erl:273: :application_master.start_it_old/4

Is there another step to do to make it work ?

Upvotes: 2

Views: 286

Answers (2)

Kernael
Kernael

Reputation: 3280

Just found the convenient mix option to pass :

{:qrcode, git: "https://github.com/komone/qrcode", app: false}

in order to prevent Mix from trying to load the package application file.

https://hexdocs.pm/mix/Mix.Tasks.Deps.html

Note : you can use the :compile option to get rid of the manual compilation of an Emakefile package, in this case :

{:qrcode, git: "https://github.com/komone/qrcode", app: false, compile: "erl -make"}

Upvotes: 2

Steve Pallen
Steve Pallen

Reputation: 4517

EDIT

My example below is for including Erlang source in an Elixir project, not as a dependency as the question asked. I'm leave the post here just in case it can help others how are trying to get their Erlang code compiled.

Its been a while since I've done it, but looking back to a previous project, I see the following in my mix.exs file:

def project do
  [ app: :mdse,
    # ...
    erlc_paths: ["./lib/mdse/rpc/src", "src"]
  ]
end

That should get it compile automatically with mix.

After looking at source of the qrcode you provided, its not an app. So I don't believe you can add it your applications: list. Instead, you should be able to use it as any Erlang library like :qrcode.encode(...).

Upvotes: 0

Related Questions