在Elixir中使用Erlang库 [英] Using Erlang library with Elixir
问题描述
尝试在Elixir项目中使用Erlang库时遇到一个小问题。
问题中的库是 erl8583
用于ISO-8583消息的打包和解包。
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.
我发现了 erl8583
的github存储库,并将我的 mix.exs
调整为以下内容:
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
当我运行 mix deps.get
和 mix deps.compile
,它运行就很顺利。
When I run mix deps.get
and mix deps.compile
, it runs smoothly.
然后,我尝试使用 iex -S mix
启动IEx会话,并获得以下错误:
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
它说找不到_build / dev / lib / erl8583 / ebin / erl8583.app
中的应用文件。据我了解,mix应该只是从 deps / erl8583 / src
中抓取该文件并包含在其中(该文件存在,我检查过)。
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).
我尝试将文件从 deps
手动复制到 _build
,但是没有成功。我在做什么错?
I tried to manually copy the file from deps
to _build
but no success. What am I doing wrong?
推荐答案
erl8583
应用程序的源 .app
文件的名称错误。 .app
文件通常位于Erlang应用程序的 ebin
目录中。如果它是用于生成 .app
文件的源文件,则应将其命名为 .app.src
。如果重命名,它将起作用,如下面的shell会话所示:
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)>
这篇关于在Elixir中使用Erlang库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!