Close and Go BackBack to Viget

Installing Sphinx on OS X Leopard

Clinton R. Nixon
Clinton R. Nixon, Senior Developer, 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 02: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 04: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 09: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 04: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 05:46 AM

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

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

Thanks for the great tutorial !

Adam Fortuna said on 08/06 at 02: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 08:17 AM

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

Trackback URL:

A Development Community for Viget Labs and Beyond

Every team member here at Viget Labs strives to be an innovator. We members of the development team are no different - that's why we're constantly engaging in community discussions and exploring the unknown that is the next generation of open-source web applications.

Viget Is Hiring!

Viget has job openings for Ruby Developers, Interns, and Front-End Developers. Learn More »

Recent Comments

I have used several different strategies for achieving this, and have settled on the plugin seed_fu to accomplish this task. Because it uses plain ruby files you have quite a few more options for manipulating your seed data as opposed to using fixtures. I have found that this lets me create seed data that is much less brittle than fixtures can be. You can find seed_fu on...