Table of contents

PHP 5 Configure error in Mac: Undefined symbols for architecture x86_64: "_libiconv", referenced

PHP Aug 08, 2020 Viewed 25 Comments 0

Issue

In Mac OS, I compile the source code of PHP 5, include 5.4.45/5.5.38/5.6.40. Run the following commands.

$ ./configure  --prefix=/opt/php-5.4.45 --enable-fpm --with-mysql
$ make

But when I run make, I get the error message saying:

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
      ...

Solution

By default, libiconv is installed on Mac, but it is not suitable for PHP 5.

1. Install libiconv

Install libiconv with brew.

brew install libiconv

Check the path of libiconv.dylib, my computer is /usr/local/Cellar/libiconv/1.16/lib/libiconv.dylib.

2. Edit Makefile

Open the file of Makefile in the current directory, search for -liconv, and find the following line.

EXTRA_LIBS = -lresolv -liconv -liconv -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm

Delete the -liconv words, and add the libiconv.dylib path at the end of the line.

- EXTRA_LIBS = -lresolv -liconv -liconv -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm

+ EXTRA_LIBS = -lresolv -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm -lxml2 -lz -licucore -lm /usr/local/Cellar/libiconv/1.16/lib/libiconv.dylib

3. Run make again

$ make
$ sudo make install
Updated Aug 08, 2020