2013-06-25 27 views
3

我翻看了StackOverflow上的問題,並搜索了一個設置用於包裝C++庫的鋼筋基本NIF項目的示例。你如何用鋼筋設置Erlang NIF項目?

我用庫項目在GitHub上作爲指導:

https://github.com/tuncer/re2

我的項目是在這裏:

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_hookrebar.configpost_hook被完全忽略:

$ rebar compile 
==> emutton (compile) 
$ rebar clean 
==> emutton (clean) 

因爲我已經克隆tuncer的RE2綁定項目,當我這樣做:沒有來自rebar顯示輸出的

{pre_hooks, [{compile, "c_src/build_deps.sh"}]}. 
{post_hooks, [{clean, "c_src/build_deps.sh clean"}]}. 

例子一個rebar compile看到他的build_deps.sh腳本的輸出。在我的權限匹配他的:

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

任何想法我在這裏失蹤?我相信鋼筋配置正確,可以調用腳本並進行編譯。

回答

2

你的問題是,在你的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). 
+0

謝謝尼姆 - 我選擇了第二種方法。我沒有看到如何控制共享庫的名稱,它始終是「emtn_drv.so」(不管我如何命名文件/ etc)。 這裏提交更改: https://github.com/project-z/emutton/commit/2e7eed36ebbff39681a85860fc5fdcedda58fe1b – lenards

+0

其實我想通了,我的問題,我的螺紋鋼。config文件實際上被命名爲'「rebar.config」',最後有兩個空格。我甚至不願意承認我犯了這個錯誤,但我不得不承認螺紋鋼郵件列表上的人員已經足夠了,可以試着回答我的問題。所以,我的愚蠢的錯誤。 現在我的'rebar.config'正確命名了,emtn.so&emtn_drv.so正確地在'/ priv /'中構建。 – lenards

相關問題