I'm having a small issue trying to use a Erlang library within an Elixir project.
The library in question is the erl8583
for ISO-8583 message packing and unpacking.
I found a github repository for erl8583
, and adjusted my mix.exs
to the following:
defmodule Iso.Mixfile do
use Mix.Project
def project do
[app: :iso,
version: "0.0.1",
elixir: "~> 1.0",
build_embedded: Mix.env == :prod,
start_permanent: Mix.env == :prod,
deps: deps]
end
def application do
[applications: [:logger]]
end
defp deps do
[{:erl8583, github: "mgwidmann/erl8583"}]
end
end
When I run mix deps.get
and mix deps.compile
, it runs smoothly.
Then, I try to start a IEx session with iex -S mix
, and get the following error:
Unchecked dependencies for environment dev:
* erl8583 (git://github.com/mgwidmann/erl8583.git)
could not find an app file at _build/dev/lib/erl8583/ebin/erl8583.app. This may happen if the dependency was not yet compiled, or you specified the wrong application name in your deps, or the dependency indeed has no app file (then you can pass app: false as option)
** (Mix) Can't continue due to errors on dependencies
It says it could not find an app file at _build/dev/lib/erl8583/ebin/erl8583.app
. As I understand, mix should have just grabbed that file from deps/erl8583/src
and included there (that file exists, I checked).
I tried to manually copy the file from deps
to _build
but no success. What am I doing wrong?
To call an Erlang function from Elixir, you call the Erlang function using the module name as an atom. For example, to call the strong_rand_bytes/1 function of Erlang's crypto module, you'd use: :crypto. strong_rand_bytes(16) .
In order to create our own modules in Elixir, we use the defmodule macro. The first letter of the module must be in uppercase. We use the def macro to define functions in that module. The first letter of every function must be in lowercase (or underscore):
The erl8583
application's source .app
file is misnamed. A .app
file normally lives in the ebin
directory for an Erlang application; if it's a source file used to generate a .app
file, it should be named .app.src
instead. If you rename it, it will work, as my shell session below shows:
$ mix deps.get
* Getting erl8583 (https://github.com/mgwidmann/erl8583.git)
Cloning into '/private/tmp/m/deps/erl8583'...
remote: Counting objects: 3468, done.
remote: Compressing objects: 100% (4/4), done.
remote: Total 3468 (delta 1), reused 0 (delta 0), pack-reused 3464
Receiving objects: 100% (3468/3468), 1002.71 KiB | 618.00 KiB/s, done.
Resolving deltas: 100% (2640/2640), done.
Checking connectivity... done.
$ mv ./deps/erl8583/src/erl8583.app ./deps/erl8583/src/erl8583.app.src
$ mix deps.compile
==> erl8583 (compile)
Compiled src/erl8583_message_helpers.erl
Compiled src/erl8583_message.erl
Compiled src/erl8583_marshaller_xml.erl
Compiled src/erl8583_marshaller_ebcdic.erl
Compiled src/erl8583_marshaller_json.erl
Compiled src/erl8583_marshaller_binary.erl
Compiled src/erl8583_marshaller_ascii.erl
Compiled src/erl8583_fields_2003.erl
Compiled src/erl8583_fields_1993.erl
Compiled src/erl8583_fields.erl
Compiled src/erl8583_marshaller.erl
src/erl8583_convert.erl:133: Warning: variable 'AsciiHex' is unused
src/erl8583_convert.erl:136: Warning: variable 'IntValue' is unused
Compiled src/erl8583_convert.erl
$ iex -S mix
Erlang/OTP 18 [erts-7.0] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:10] [hipe] [kernel-poll:false]
Generated iso app
Interactive Elixir (1.1.0-rc.0) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With