Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to compile PHP and I kept getting this error during 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

The ./configure command of PHP has the iconv folder pointing to /opt/local, so the macport iconv library is used (which is installed using the the +universal flag). Doing file I get:

/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

I tried then install the iconv library manually, forcing only the 64-bit architecture (I installed it in /usr/local) and it works. The output of file is:

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

Why is this happening? I manage to build and make PHP work with the manual installation, but I don't understand.

share|improve this question

migrated from serverfault.com Feb 26 '12 at 15:42

This question came from our site for system and network administrators.

up vote 5 down vote accepted

The MacPorts iconv library renames the symbols to _libiconv_open and _libiconv_close. That's why PHP couldn't find them, not because of the forced 64-bit. Run nm /opt/local/lib/libiconv.dylib vs nm /usr/lib/libiconv.dylib (in 10.7.3).

share|improve this answer
    
Oh, now I understand. Thank you! – entropid Feb 26 '12 at 19:04
    
Thanks, I was able to get it working by pointing PHP to the non-macports version using --with-iconv-dir=/usr/lib – simianarmy Jun 27 '12 at 17:19

In my case --with-iconv-dir=/usr/lib was not enough, I think this option don't work. So I manually renamed /opt/local/lib/libiconv.dylib to /opt/local/lib/libiconv.dylib.bak and after building renamed back.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .