在 OS X 上编译 PHP:iconv 仅在强制为 64 位时才有效

在 OS X 上编译 PHP:iconv 仅在强制为 64 位时才有效

我正在尝试编译 PHP,但在以下过程中不断收到此错误make

Undefined symbols for architecture x86_64:
  "_iconv_open", referenced from:
      __php_iconv_mime_decode in iconv.o
      __php_iconv_strlen in iconv.o
      _php_iconv_string in iconv.o
      __php_iconv_strpos in iconv.o
      _zif_iconv_substr in iconv.o
      _zif_iconv_mime_encode in iconv.o
      _php_iconv_stream_filter_factory_create in iconv.o
      ...
  "_iconv_close", referenced from:
      __php_iconv_mime_decode in iconv.o
      __php_iconv_strlen in iconv.o
      _php_iconv_string in iconv.o
      __php_iconv_strpos in iconv.o
      _zif_iconv_substr in iconv.o
      _zif_iconv_mime_encode in iconv.o
      _php_iconv_stream_filter_dtor in iconv.o
      ...
ld: symbol(s) not found for architecture x86_64
collect2: ld returned 1 exit status

PHP命令./configure的 iconv 文件夹指向/opt/local,因此使用 macport iconv 库(使用 标志安装+universal)。执行后file我得到:

/opt/local/lib/libiconv.dylib: Mach-O universal binary with 2 architectures
/opt/local/lib/libiconv.dylib (for architecture i386):  Mach-O dynamically linked shared library i386
/opt/local/lib/libiconv.dylib (for architecture x86_64):    Mach-O 64-bit dynamically linked shared library x86_64

然后我尝试手动安装 iconv 库,只强制 64 位架构(我在 中安装了它/usr/local),它可以工作。 的输出file是:

/usr/local/lib/libiconv.dylib: Mach-O 64-bit dynamically linked shared library x86_64

为什么会发生这种情况?我设法通过手动安装构建并使 PHP 运行,但我不明白。

答案1

MacPorts iconv 库将符号重命名为_libiconv_open_libiconv_close。这就是 PHP 找不到它们的原因,而不是因为强制 64 位。运行nm /opt/local/lib/libiconv.dylibvs nm /usr/lib/libiconv.dylib(在 10.7.3 中)。

答案2

在我的例子中--with-iconv-dir=/usr/lib这还不够,我认为这个选项不起作用。所以我手动重命名/opt/local/lib/libiconv.dylib/opt/local/lib/libiconv.dylib.bak,并在构建后重命名回来。

相关内容