2013-04-04 58 views
1

我在OSX 10.6 Snow Leopard上玩http://www.erlang.org/doc/tutorial/nif.html。我在運行該示例時遇到了一些麻煩。Erlang運行時錯誤的體系結構?

我編譯使用:

gcc -o complex_nif.so -fpic -I/usr/local/lib/erlang/usr/include -flat_namespace -undefined suppress complex.c complex_nif.c 

和使用Erlang的運行:

Erlang R15B01 (erts-5.9.1) [source] [smp:4:4] [async-threads:0] [hipe] [kernel-poll:false] 

Eshell V5.9.1 (abort with ^G) 
1> c(complex). 
{error,on_load_failure} 

=ERROR REPORT==== 4-Apr-2013::15:24:51 === 
Error in process <0.37.0> with exit value: {{badmatch,{error,{load_failed,"Failed to load NIF library: 'dlopen(./complex_nif.so, 2): no suitable image found. Did find:\n  ./complex_nif.so: mach-o, but wrong architecture'"}}},[{complex,init,0,[{file,"... 


=ERROR REPORT==== 4-Apr-2013::15:24:51 === 
The on_load function for module complex returned {{badmatch, 
                {error, 
                {load_failed, 
                "Failed to load NIF library: 'dlopen(./complex_nif.so, 2): no suitable image found. Did find:\n\t./complex_nif.so: mach-o, but wrong architecture'"}}}, 
                [{complex,init,0, 
                [{file,...},{...}]}, 
                {code_server, 
                '-handle_on_load/4-fun-0-', 
                1, 
                [{...}|...]}]} 

我看到,我找到.so文件。但是erlang並不喜歡它所編譯的架構,erlang更喜歡哪種架構?

+0

32位VS 64位? – 2013-04-04 22:48:07

+0

@RobertoAloi,我已經嘗試了-m32和-m64,他們沒有任何區別。 – 2013-04-04 22:49:00

回答

3

驗證您的Erlang運行系統使用的體系結構。例如: -

$ which erlc 
/usr/local/bin/erlc 
$ file /usr/local/bin/erlc 
/usr/local/bin/erlc: Mach-O 64-bit executable x86_64 

確保您的庫上面的體系結構相匹配:

$ file complex_nif.so 
complex_nif.so: Mach-O 64-bit executable x86_64 

如果它們不匹配,編譯庫與-arch i386(或-arch x86_64)標誌。

+0

The do match .. sorta'complex.so:Mach-O動態鏈接共享庫i386'和'/ usr/local/bin/erlc:Mach-O可執行文件i386' – 2013-04-05 01:31:46

+0

我讓它們完全匹配 - 仍然是相同的錯誤.. – 2013-04-05 01:33:58

+1

你能顯示編譯命令的全部序列,相對錯誤和'file'命令的輸出嗎? – 2013-04-05 14:54:36