我浏览了StackOverflow上的问题,并用谷歌搜索了一下在rebar中为包装C++库而设置一个基本的NIF项目的示例。
我曾经将GitHub上的库项目作为指南:
我的项目在这里:
https://github.com/project-z/emutton/
当我执行rebar compile && rebar eunit时,我在eunit测试中得到一个失败,因为它找不到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当我调用rebar compile时,它只生成一个驱动程序文件emtn_drv.so,而没有生成emtn.so:
$ tree priv
priv
└── emtn_drv.so
0 directories, 1 file我在c_src/build_deps.sh中有一个echo语句,当我调用rebar clean时看不到输出。似乎我的pre_hook和rebar.config中的post_hook被完全忽略了:
{pre_hooks, [{compile, "c_src/build_deps.sh"}]}.
{post_hooks, [{clean, "c_src/build_deps.sh clean"}]}.rebar未显示输出的示例:
$ rebar compile
==> emutton (compile)
$ rebar clean
==> emutton (clean)因为我已经克隆了tuncer的RE2绑定项目,并且当我执行rebar compile时,可以看到他的build_deps.sh脚本的输出。我的权限与他的权限一致:
-rwxr-xr-x 1 ajl staff 891B Jun 25 12:30 c_src/build_deps.sh你知道我错过了什么吗?我相信rebar配置正确,可以调用脚本并进行编译。
发布于 2013-06-26 05:08:10
您的问题是rebar.config中的行
https://github.com/project-z/emutton/blob/master/rebar.config%20#L1
与您尝试加载的内容不匹配
https://github.com/project-z/emutton/blob/master/src/emtn.erl#L25
您应该将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或将emtn.erl更改为
erlang:load_nif(filename:join(PrivDir, "emtn_drv"), 0).https://stackoverflow.com/questions/17306235
复制相似问题