7

我正在尝试在 Mac OS X Lion 上编译来自 Erlang ( http://www.erlang.org/doc/man/erl_nif.html ) 的 NIF 测试。我无法编译它。我是否缺少编译器标志?这是我得到的错误:

Computer:~ me $ gcc -fPIC -shared -o niftest.so niftest.c -I /usr/local/Cellar/erlang/R14B02/lib/erlang/usr/include/
Undefined symbols for architecture x86_64:
  "_enif_make_string", referenced from:
      _hello in ccXfh0oG.o
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

我也试过这个,-m32但它说也没有 i386 架构。

谢谢!

4

3 回答 3

13

对于 64 位 Erlang,以下对我有用:

gcc -undefined dynamic_lookup -dynamiclib niftest.c -o niftest.so \
    -I /usr/local/Cellar/erlang/R14B02/lib/erlang/usr/include
于 2011-11-27T20:54:14.700 回答
2

似乎您的问题不是架构而是 undefined symbol _enif_make_string,这意味着您必须使用选项链接到您的enif库,无论它是什么。-l另外,我已经很长时间没有为 OS X 构建共享库了,但我认为正确的标志是 is-dynamiclib和 not -shared,并且你不必在-I.

于 2011-11-27T19:43:24.797 回答
1

在编译 nif 而不是 -shared 时尝试使用这些标志

-bundle -flat_namespace -undefined suppress
于 2011-11-27T20:30:15.450 回答