Compiling libreadline on Mac OS X

I just realized that I never posted my recipe for configuring and installing libreadline on Mac OS X. I need it for use with PostgreSQL, and don't fully understand why Apple has not yet included it with Mac OS X. Maybe it'll be in Tiger?

In the meantime, it turns out to be pretty easy to configure it and build it yourself, assuming you have the developer tools (Xcode) installed. The only thing that's different from any other Unix is that the support/shobj-conf must be modified to be able to find other libraries installed on Mac OS X. Here's a shell script I whipped up that can do the whole thing for you, soup-to-nuts.

export VERSION=4.3
curl -O$VERSION.tar.gz
tar zxvf readline-$VERSION.tar.gz
cd readline-$VERSION
perl -i.bak -p -e \
  "s/SHLIB_LIBS=.*/SHLIB_LIBS='-lSystem -lncurses -lcc_dynamic'/g" \
sudo make install

Hope that this helps others!


Chris Dolan wrote:


Readline has been ported to OSX via the Fink project ( You can apt-get their .deb binaries to simplify the proces of installing most of the popular open source unix-ish libraries that Apple doesn't provide.

Theory wrote:

Re: Fink

Thanks, but I never use Fink. I don't like packaging systems because they break dependencies when you compile some things and install others from packages. So I tend to compile all my Unix apps from source.

Ian Osgood wrote:

No longer works on Tiger

Thanks for this! I'm trying to build readline because the Haskell interpreter GHCi requires 5.0 to be installed (Tiger only has 2.0). The above script no longer seems to work for either Tiger or VERSION=5.0; the only stuff installed in /usr/local/lib is "libreadline." and "libreadline.a", whereas I was expecting a dylib. Think you could up this for Tiger?

Theory wrote:

Re: No longer works on Tiger


I haven't been able to get it to compile shared libs on Tiger. I have no idea why. See this discussion for details.


Justin wrote:

Thanks for the script, just the solution I was looking for!