【发布时间】:2013-03-15 02:39:38
【问题描述】:
如果我自己编写 escript,我可以使用 nif,但是当我使用 rebar escriptize 时,找不到 nif 函数。我认为这是因为 *.so 对象没有像梁文件那样被打包。这是一个简单的例子;
rebar.config:
{deps, [
{'jiffy', "", {git, "https://github.com/davisp/jiffy.git", {branch, master}}}
]}.
{escript_incl_apps, [jiffy]}.
%% I tried this to see what happens if the so got in there but didn't help
{escript_incl_extra, [{"deps/jiffy/priv/jiffy.so", "/path/to/my/proj"}]}.
test.erl:
-module(test).
-export([main/1]).
main(_Args) ->
jiffy:decode(<<"1">>),
ok.
rebar get-deps 编译 escriptize
./测试
结果是
escript: exception error: undefined function jiffy:decode/1
in function test:main/1 (src/test.erl, line 7)
in call from escript:run/2 (escript.erl, line 741)
in call from escript:start/1 (escript.erl, line 277)
in call from init:start_it/1
in call from init:start_em/1
有没有办法克服这个问题?
【问题讨论】:
-
从错误看来,它是找不到的
jiffy.beam,而不是*.so。也许escriptize只考虑来自ebin的光束,忽略依赖关系'ebins? -
@Ed'ka,不,如果你添加一个不是 nif 的依赖项,它可以正常工作。
-
但是如果你尝试调用
jiffy:decode/1并从priv中删除jiffy.so你应该得到Failed to load NIF library错误,而不是undefined function
标签: erlang rebar erlang-nif