Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP compile fails with undefined symbols for architecture x86_64, libiconv on macOS Sierra

I have upgraded a Mac to macOS 10.12.0 Sierra, and am trying to upgrade PHP to version 7.0.9, but 'make test' fails with:

Undefined symbols for architecture x86_64:
  "_libiconv", referenced from:
      _zif_iconv_substr in iconv.o
      _zif_iconv_mime_encode in iconv.o
      _php_iconv_string in iconv.o
      __php_iconv_strlen in iconv.o
      __php_iconv_strpos in iconv.o
      __php_iconv_appendl in iconv.o
      _php_iconv_stream_filter_append_bucket in iconv.o
      ...
  "_libiconv_close", referenced from:
      _zif_iconv_substr in iconv.o
      _zif_iconv_mime_encode in iconv.o
      _php_iconv_string in iconv.o
      __php_iconv_strlen in iconv.o
      __php_iconv_strpos in iconv.o
      __php_iconv_mime_decode in iconv.o
      _php_iconv_stream_filter_factory_create in iconv.o
      ...
  "_libiconv_open", referenced from:
      _zif_iconv_substr in iconv.o
      _zif_iconv_mime_encode in iconv.o
      _php_iconv_string in iconv.o
      __php_iconv_strlen in iconv.o
      __php_iconv_strpos in iconv.o
      __php_iconv_mime_decode in iconv.o
      _php_iconv_stream_filter_factory_create in iconv.o
      ...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [libs/libphp7.bundle] Error 1

I compiled it with:

./configure --prefix=/usr/local/php5 --mandir=/usr/share/man --infodir=/usr/share/info --sysconfdir=/etc --with-config-file-path=/etc --with-zlib --with-zlib-dir=/usr --with-openssl=/usr/local --enable-exif --enable-ftp --enable-mbstring --enable-mbregex --enable-sockets --with-pdo-mysql=mysqlnd --with-mysqli=mysqlnd --with-apxs2=/usr/local/apache2/bin/apxs --enable-zip --with-curl

and have tried adding different '--with-iconv-dir=' options but always get the same undefined symbols error.

I have downloaded and compiled libiconv to no avail. Even configured the compile with:

CFLAGS='-arch x86_64' CCFLAGS='-arch x86_64' CXXFLAGS='-arch x86_64' ./configure

but that made no difference. Any suggestions?

Any help would be much appreciated.

like image 922
jlbrown Avatar asked Oct 21 '16 02:10

jlbrown


2 Answers

This might solve the problem

vim Makefile
find EXTRA_LDFALGS and EXTRA_LDFLAGS_PROGRAMS
remove L/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/lib 
like image 126
阮佳佳 Avatar answered Oct 23 '22 13:10

阮佳佳


  1. brew install libiconv (libiconv will install in /usr/local/opt/libiconv/)
  2. find EXTRA_LIBS variable in MakeFile.
  3. change -liconv to /usr/local/opt/libiconv/lib/libiconv.dylib

Here is the reason:

  • Mac os has its own libiconv.dylib in dir/usr/lib/libiconv.dylib, which do not contains _libiconv _libiconv_close . founctions. Update to a new libiconv version and reference to it will solve the case
like image 28
lili-timer Avatar answered Oct 23 '22 12:10

lili-timer