Installing Sphinx on OS X Leopard

Clinton R. Dreisbach, Former Viget

Article Category: #Code

Posted on

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.

Related Articles