PHP5.3+GD+OpenSSL compilation on Mac OS X fails with iconv symbol errors? Here’s the fix.

I nearly broke my head trying to compile PHP 5.3.6 on my Mac with GD and OpenSSL support enabled. For reference purposes, here is what my configuration looks like and what errors I were running into, while trying to make.

./configure \
    --prefix=/opt/php \
    --enable-fpm \
    --with-mysql=mysqlnd \
    --with-zlib-dir=~/nginx-build/zlib-1.2.5 \
    --with-curl \
    --enable-mbstring \
    --disable-debug  \
    --with-gd \
    --with-jpeg-dir=/opt/local \
    --with-png-dir=/opt/local \
    --with-config-file-path=/opt/php/etc/php.ini

make then chooses to fail with the following message.

Undefined symbols:
  "_iconv", referenced from:
      __php_iconv_strlen in iconv.o
      _php_iconv_string in iconv.o
      _php_iconv_string in iconv.o
      __php_iconv_strpos in iconv.o
      __php_iconv_appendl in iconv.o
      __php_iconv_appendl in iconv.o
      _zif_iconv_substr in iconv.o
      _zif_iconv_mime_encode in iconv.o
      _zif_iconv_mime_encode in iconv.o
      _zif_iconv_mime_encode in iconv.o
      _zif_iconv_mime_encode in iconv.o
      _zif_iconv_mime_encode in iconv.o
      _zif_iconv_mime_encode in iconv.o
      _php_iconv_stream_filter_append_bucket in iconv.o
      _php_iconv_stream_filter_append_bucket in iconv.o
     (maybe you meant: _iconv_functions, _zif_iconv_mime_decode , _zif_iconv_substr , _zif_iconv_strlen ,
zif_iconv_strpos , _zif_ob_iconv_handler , _iconv_module_entry , _iconv_globals , _zif_iconv_mime_encode ,
_zif_iconv_get_encoding , _php_iconv_string , _zif_iconv_mime_decode_headers , cstring=ob_iconv_handler ,
_php_if_iconv , _zif_iconv_set_encoding , _zif_iconv_strrpos )
ld: symbol(s) not found
collect2: ld returned 1 exit status

The fix

The fix requires patching ext/iconv/iconv.c from the PHP source directory. Open ext/iconv/iconv.c in a text editor and make the following changes.

  1. At line 54, delete the following three lines:

    #ifdef HAVE_LIBICONV
    #undef iconv
    #endif
    
  2. At line 185, delete the following three lines:

    #if defined(HAVE_LIBICONV) && defined(ICONV_ALIASED_LIBICONV)
    #define iconv libiconv
    #endif
    

That should fix it. Go back and run make again and it should compile PHP successfully this time.

Here is the patch if you like:

--- iconv.c.original	2011-06-22 12:37:14.000000000 +0530
+++ iconv.c	2011-06-22 12:09:59.000000000 +0530
@@ -51,10 +51,6 @@
 #include 
 #endif

-#ifdef HAVE_LIBICONV
-#undef iconv
-#endif
-
 #include "ext/standard/php_smart_str.h"
 #include "ext/standard/base64.h"
 #include "ext/standard/quot_print.h"
@@ -182,10 +178,6 @@
 }
 /* }}} */

-#if defined(HAVE_LIBICONV) && defined(ICONV_ALIASED_LIBICONV)
-#define iconv libiconv
-#endif
-
 /* {{{ typedef enum php_iconv_enc_scheme_t */
 typedef enum _php_iconv_enc_scheme_t {
 	PHP_ICONV_ENC_SCHEME_BASE64,
  • Bruce

    Thanks for the fix. I used this to compile PHP 5.3.9 –with-iconv (and GD etc) on Mac OS X Lion.

Copyright (c) 2000-2011 Alex N J. All rights reserved.
All and any opinion expressed here are solely mine and do not represent the views of my employer or any other person or organization related to me. Entries (RSS) and Comments (RSS).