0

OSX 10.6 Snow Leopardでhttp://www.erlang.org/doc/tutorial/nif.htmlをいじっています。例の実行に問題があります。

私は以下を使用してコンパイルします:

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 はどのアーキテクチャを好みますか?

4

1 に答える 1

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) フラグを指定してライブラリをコンパイルします。

于 2013-04-04T23:14:14.780 に答える