如何使用钢筋设置Erlang NIF项目? 我在StAcExobe上浏览了这个问题,并在Google中搜索了一个例子,在ReBar中建立一个基本的NIF项目,用于包装C++库。p>

如何使用钢筋设置Erlang NIF项目? 我在StAcExobe上浏览了这个问题,并在Google中搜索了一个例子,在ReBar中建立一个基本的NIF项目,用于包装C++库。p>,erlang,rebar,erlang-nif,Erlang,Rebar,Erlang Nif,我曾以GitHub上的库项目为指导: 我的项目在这里: 当我执行rebar编译和&rebar eunit时,eunit测试失败,因为它找不到emtn。因此: $ rebar compile && rebar eunit ==> emutton (compile) ==> emutton (eunit) undefined *** test module not found *** **emtn =ERROR REPORT==== 25-Jun-2013::12

我曾以GitHub上的库项目为指导:

我的项目在这里:

当我执行
rebar编译和&rebar eunit
时,eunit测试失败,因为它找不到
emtn。因此

$ rebar compile && rebar eunit 
==> emutton (compile)
==> emutton (eunit)
undefined
*** test module not found ***
**emtn

=ERROR REPORT==== 25-Jun-2013::12:21:55 ===
The on_load function for module emtn returned {error,
                                               {load_failed,
                                                "Failed to load NIF library: 'dlopen(/.../source/emutton/priv/emtn.so, 2): image not found'"}}
=======================================================
  Failed: 0.  Skipped: 0.  Passed: 0.
One or more tests were cancelled.
ERROR: One or more eunit tests failed.
ERROR: eunit failed while processing /.../source/emutton: rebar_abort
$ tree priv 
priv
└── emtn_drv.so

0 directories, 1 file
当我调用
rebar compile
时,它只生成一个驱动程序文件,
emtn\u drv.so
和no
emtn.so

$ rebar compile && rebar eunit 
==> emutton (compile)
==> emutton (eunit)
undefined
*** test module not found ***
**emtn

=ERROR REPORT==== 25-Jun-2013::12:21:55 ===
The on_load function for module emtn returned {error,
                                               {load_failed,
                                                "Failed to load NIF library: 'dlopen(/.../source/emutton/priv/emtn.so, 2): image not found'"}}
=======================================================
  Failed: 0.  Skipped: 0.  Passed: 0.
One or more tests were cancelled.
ERROR: One or more eunit tests failed.
ERROR: eunit failed while processing /.../source/emutton: rebar_abort
$ tree priv 
priv
└── emtn_drv.so

0 directories, 1 file
我在
c\u src/build\u deps.sh
中有一个echo语句,当我调用
rebar clean
时,我看不到输出。它的行为似乎好像完全忽略了
rebar.config
中的我的
pre_hook
post_hook

{pre_hooks, [{compile, "c_src/build_deps.sh"}]}.
{post_hooks, [{clean, "c_src/build_deps.sh clean"}]}.
钢筋未显示输出的示例:

$ rebar compile 
==> emutton (compile)
$ rebar clean 
==> emutton (clean)
因为我已经克隆了tuncer的RE2绑定项目,当我执行
钢筋编译时
可以看到他的build_deps.sh脚本的输出。我的权限与他的权限匹配:

-rwxr-xr-x  1 ajl  staff   891B Jun 25 12:30 c_src/build_deps.sh

你知道我错过了什么吗?我相信rebar配置正确,可以调用脚本并进行编译

您的问题是,您的rebar.config中的行

与您尝试加载的内容不匹配

您应该将rebar.config更改为

{port_specs, [{"priv/emtn.so",["c_src/emtn_nif.c"]}]}.
并将emtn.erl更改为

erlang:load_nif(filename:join(PrivDir, "emtn"), 0).  % ?MODULE is an atom, I believe you need a string
erlang:load_nif(filename:join(PrivDir, "emtn_drv"), 0).
或将emtn.erl更改为

erlang:load_nif(filename:join(PrivDir, "emtn"), 0).  % ?MODULE is an atom, I believe you need a string
erlang:load_nif(filename:join(PrivDir, "emtn_drv"), 0).

谢谢Nym-我选择了第二种方法。我不知道如何控制共享库的名称,它总是“emtn_drv.so”(无论我如何命名文件/etc)。这里是提交的更改:我实际上解决了我的问题,我的rebar.config文件实际上名为
“rebar.config”
,末尾有两个空格。我甚至不愿意承认我犯了这个错误,但我不得不向力霸邮件列表上的人承认,他们很好地回答了我的问题。所以,我犯了个愚蠢的错误。现在,我已经正确地命名了
rebar.config
,emtn.so和emtn\u drv.so已经正确地内置在
/priv/
中。