Close and Go BackBack to Viget

Installing Sphinx on OS X Leopard

Clinton R. Nixon
Clinton R. Nixon, Development Director, April 17, 2008 8

I am working on a project where we are using Ultrasphinx as the search solution for the site. I had to install Sphinx to make this work, and I soon found out that the version of Sphinx in MacPorts is one release too old to work with Ultrasphinx. (You need to use the latest release of version 0.9.8.) I very much like using package management, but sometimes you have to bite the bullet and compile something yourself.

When I tried to compile Sphinx with the tried-and-true ./configure; make; make install, I ran into some serious problems. It wouldn’t compile, and gave me this error:

g++  -Wall -g -D_FILE_OFFSET_BITS=64 -O3 -DNDEBUG   
-o indexer  indexer.o libsphinx.a  -L/opt/local/lib 
-L/opt/local/lib/mysql5/mysql -lmysqlclient -L/opt/local/lib 
-lz -lm  -L/opt/local/lib -lssl -lcrypto  -liconv -lexpat  
-L/usr/local/lib
Undefined symbols:
  "_iconv_close", referenced from:
      xmlUnknownEncoding(void*, char const*, XML_Encoding*)in libsphinx.a(sphinx.o)
  "_iconv", referenced from:
      xmlUnknownEncoding(void*, char const*, XML_Encoding*)in libsphinx.a(sphinx.o)
  "_iconv_open", referenced from:
      xmlUnknownEncoding(void*, char const*, XML_Encoding*)in libsphinx.a(sphinx.o)
ld: symbol(s) not found
collect2: ld returned 1 exit status
make[2]: *** [indexer] Error 1
make[1]: *** [all] Error 2
make: *** [all-recursive] Error 1

It turns out that I needed to compile the latest versions of the expat XML parser and iconv. Here’s a quick guide to how I got everything working:

Download iconv from the GNU project and compile it.

curl -O http://ftp.gnu.org/gnu/libiconv/libiconv-1.12.tar.gz
tar zxvf libiconv-1.12.tar.gz
cd libiconv-1.12
./configure --prefix=/usr/local
make
sudo make install
cd ..

I’m installing everything in /usr/local, and I suggest you do, too. I don’t want to mix up the programs I compile with the OS X system libraries and binaries (/usr) or MacPorts’ libraries and binaries (/opt/local).

Download expat and compile it.

curl -O http://internap.dl.sourceforge.net/sourceforge/expat/expat-2.0.1.tar.gz
tar zxvf expat-2.0.1.tar.gz
cd expat-2.0.1
./configure --prefix=/usr/local
make
sudo make install
cd ..

Download Sphinx and compile it. There’s a new flag given to configure this time, specifying the location of my MySQL installation. I installed it via MacPorts; if you installed it differently, you will have to change this flag. Also, you may want to go to the Sphinx download page to see if there’s a new version of Sphinx out. The version current while I’m writing this is a release candidate, and a finished release of 0.9.8 may be out by the time you read this.

curl -O http://www.sphinxsearch.com/downloads/sphinx-0.9.8-rc2.tar.gz
tar zxvf sphinx-0.9.8-rc2.tar.gz
cd sphinx-0.9.8-rc2
./configure --prefix=/usr/local --with-mysql=/opt/local/lib/mysql5
make
sudo make install
cd ..

The install is quick and easy, but certainly wasn’t when I was trying to figure out why Sphinx wouldn’t compile.


Adam said on 05/07 at 03:30 PM

I just ran into this issue—this really helped me out, worked great on the first time through.  Thanks for the writeup!

Jörg Battermann said on 05/16 at 05:44 PM

There’s a slightly easier way to do this:

libiconv & expat are usually already installed on someone’s system so all you need to do is twiddle a tiny line in the sphinx configure script:

http://blogwi.se/post/35063599

:)

Brian said on 05/28 at 10:37 AM

I also ran into this today when trying to upgrade to 0.9.8rc2 (from 0.9.7). Worked perfectly. Much appreciated.

sal said on 06/30 at 05:56 PM

AWESOME!

thanks much for this writeup, I tried installing sphinx and ran into some compile errors as well… Not sure they were these exact ones, but from what I remember this looks familiar.
Also, once you ran into your initial compile errors, did you just simply wipe out your /usr/local/sphinx directory and then re-compile (following the steps mentioned)?

cheers

Chris said on 07/23 at 06:46 AM

Smashing! Thanks for outlining what’s needed to be done so precisely :-)

michael bensoussan said on 08/01 at 09:56 AM

Thanks for the great tutorial !

Adam Fortuna said on 08/06 at 03:11 PM

Great tutorial! Was running across a problem installing it with iconv and this was right on the money for fixing it. Thanks!

Dennis said on 08/09 at 09:17 AM

Awesome! Thanks for taking the time to document the work around!

We're the Developers

at Viget Labs. We write about web development trends, tips, best practices, industry events, and our projects — all with an emphasis on Ruby on Rails.

Recent Comments

For translating strings you can use Rails I18n backend instead of using inflectors.

The `typus_human_name` is a patch to fix a problem in `human_name` [1].

[1] https://rails.lighthouseapp.com/projects/8994/tickets/2120-humanize-and-human_name-dont-separate-words

Contact Us

Have any questions, comments, ideas, or secrets to share? Let us know.


Sorry, you need to have Javascript enabled to use this form. (Don't blame us, blame the spammers!) If you'd like to contact us, please visit our Contact page.