PHP 5.3, iconv, OSX, Symbols Missing _libiconv

I’m not sure how many people will have this problem, but I did so this will remind me.

PHP 5.3 release, for some reason, does not like my default install of iconv. Firstly, I made the grave mistake of failing to point PHP properly at an install in /usr/local/, so replaced my OS installation of iconv with a new one. This was all well and good until I started opening apps that needed specific parts of OSX’s default iconv. So, an OSX restore later, we’re at square one. PHP keeps telling me various crap when I’m trying to compile that it didn’t work with iconv because it’s the wrong version, but would fail during make because it couldn’t find the correct symbols.

I had compiled and installed iconv (./configure –prefix=/usr/local/iconv –enable-static) then pointed PHP at that (–with-iconv=/usr/local/iconv) and it was failing during make with Undefined Symbols: “_libiconv” then some stack trace of php string functions. Great. After much Googling and cobbling together my own way to do this with trial and error and a mixture of other people’s part-baked solutions, I have come up with the following method:

  1. install iconv: ./configure –prefix=/usr/local/iconv –enable-static && make && sudo make install
  2. configure PHP with the following prefix: env LIBS=”-lresolv -liconv” ./configure ……

    Mine is:

    env LIBS=”-lresolv -liconv” ./configure \
    –enable-pdo \
    –with-apxs2=/usr/local/apache2/bin/apxs \
    –with-mysql=/usr/local/mysql \
    –with-pdo-mysql=/usr/local/mysql \
    –prefix=/usr/local/php \
    –enable-mbstring \
    –with-mysql=/usr/local/mysql \
    –enable-cli \
    –with-curl \
    –with-gd \
    –with-png-dir=/usr/local/png \
    –with-jpeg-dir=/usr/local/jpg \
    –with-freetype-dir=/usr/local/freetype \
    –with-zlib-dir=/usr/local/zlib \
    –with-mcrypt=/usr/local/mcrypt \
    –with-iconv=/usr/local/iconv

  3. After configure has finished running, hopefully there has been no problem. If there has I have no idea how to fix it. Normally this runs smooth as hell for me, this has taken me about 6 solid hours to fix and I can’t be remotely fixing everyone else’s, sorry.

    You’ll need to be modifying the Makefile generated from your ./configure. Search for the following string (without quotes) “libs/libphp$” and replace that and the next line with the following:

    libs/libphp$(PHP_MAJOR_VERSION).bundle: $(PHP_GLOBAL_OBJS) $(PHP_SAPI_OBJS)
    $(CC) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) $(PHP_GLOBAL_OBJS:.lo=.o) $(PHP_SAPI_OBJS:.lo=.o) $(PHP_FRAMEWORKS) $(EXTRA_LIBS) $(ZEND_EXTRA_LIBS) $(MH_BUNDLE_FLAGS) -o $@ && cp $@ libs/libphp$(PHP_MAJOR_VERSION).so

  4. make
  5. You can run make test if you want, but it’ll fail everything it doesn’t skip
  6. sudo make install
  7. Restart apache
  8. Everything should work fine now. If it didn’t, I’m sorry – I don’t know why. If it does, hoorah! You just saved yourself 6 hours. You owe me a beer!

Again, I must reiterate, if this doesn’t work for you I probably won’t be able to fix this or even help you slightly. This is just what worked for me. There are plenty of things you can try with a bit of Google-fu, though.

annoying problems compile configure fucking waste of time iconv leopard make osx php snow leopard symbols missing _libiconv

code, mac

OCDeveloper

I had already wasted about 6 hours over two days fudging around and rolling back crap hacks for this php upgrade. But your instructions totally worked for me. My Google-Fu is good, but slow.

My setup:
- OS X 10.5.8
- Intel
- mySQL 5.0.51b installed in usr/local

(preparation)
MACOSX_DEPLOYMENT_TARGET=10.5 CFLAGS=”-arch x86_64 -g -Os -pipe -no-cpp-precomp” CCFLAGS=”-arch x86_64 -g -Os -pipe” CXXFLAGS=”-arch x86_64 -g -Os -pipe” LDFLAGS=”-arch x86_64 -bind_at_load” export CFLAGS CXXFLAGS LDFLAGS CCFLAGS MACOSX_DEPLOYMENT_TARGET

(mhash)
./configure && make && sudo make install

(libmcrypt)
./configure && make && sudo make install

(mcrypt)
touch malloc.h
./configure && make && sudo make install

(libiconv)
./configure && make && sudo make install

(php configure)
env LIBS=”-liconv” ./configure –prefix=/usr –mandir=/usr/share/man –infodir=/usr/share/info –disable-dependency-tracking –with-apxs2=/usr/sbin/apxs –with-ldap=/usr –with-kerberos=/usr –enable-cli –with-zlib-dir=/usr –enable-trans-sid –with-xml –enable-exif –enable-ftp –enable-mbstring –enable-mbregex –enable-dbx –enable-sockets –with-iodbc=/usr –with-curl=/usr –with-config-file-path=/etc –sysconfdir=/private/etc –with-mysql-sock=/var/mysql –with-mysqli=/usr/local/mysql/bin/mysql_config –with-mysql=/usr/local/mysql –with-openssl –with-xmlrpc –with-xsl=/usr –without-pear –with-mcrypt=/usr/local/bin/mcrypt –with-iconv=/usr/local/bin/iconv

(php makefile edit)
from:
$(CC) $(MH_BUNDLE_FLAGS) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) $(PHP_GLOBAL_OBJS:.lo=.o) $(PHP_SAPI_OBJS:.lo=.o) $(PHP_FRAMEWORKS) $(EXTRA_LIBS) $(ZEND_EXTRA_LIBS) -o $@ && cp $@ libs/libphp$(PHP_MAJOR_VERSION).so
to:
$(CC) $(CFLAGS_CLEAN) $(EXTRA_CFLAGS) $(LDFLAGS) $(EXTRA_LDFLAGS) $(PHP_GLOBAL_OBJS:.lo=.o) $(PHP_SAPI_OBJS:.lo=.o) $(PHP_FRAMEWORKS) $(EXTRA_LIBS) $(ZEND_EXTRA_LIBS) $(MH_BUNDLE_FLAGS) -o $@ && cp $@ libs/libphp$(PHP_MAJOR_VERSION).so

(php make)
make
sudo make install

(toggle Web Sharing in User Preferences)

Apache, PHP, Zend Debugger and Snow Leopard are conspiring to kill me – Tom Sartain | Blog

[...] still throws undefined symbol errors. This is no longer fixable by adding -liconv to the EXTRA_LIBS in the [...]

PHP 5.3, iconv, OSX, Symbols Missing _libiconv // jspr

[...] The rest is here: PHP 5.3, iconv, OSX, Symbols Missing _libiconv // jspr [...]

Apache, PHP, Snow Leopard and Oracle conspired to kill me, but I didn’t let them! – Tom Sartain | Blog

[...] continued to throw defined symbol errors. Tried manually compiling iconv in 64-bit but that didn’t work, eventually just went with a Macports install and that worked. Also, [...]

Koodough

It works!!! thanks!
Snow Leopard 10.6.2
PHP 5.3.1
12/16/09

Jasper Tandy

No problem! Seems to be a bit hit-and-miss, but it worked for me! :D

Brandon Prudent

Indeed, this did work, and continues to work for broken PHP OS X releases. My question is, why does it work? What is going on exactly? More importantly, why isn’t this fixed as part of the release? This post is several months old.

(yeah, I realize we can’t answer the why php questions, but I’m still angry about it)

Jasper Tandy

I agree – it is annoying that there hasn’t been a fix yet, but I’m assuming that it’s OSX-only and therefore not high priority enough to give attention to!

Jay Garcia

This worked for me like a charm. Thank you very much for taking the time to post this writeup.

Jasper Tandy

No problem at all – glad you found it useful :)