OS X – Building GNU readline

A number of open source packages depend on the GNU readline library. Here are a couple of easy ways to install it on OS X.

GNU readline provides functionality for editing command history in many interactive command line applications. Some require it to build while others will just disable that functionality if the library isn’t present on your system.

It doesn’t come with the OS X operating system but there are a couple of really easy ways to get it on your Mac.

Get the binary

GNU readline is among the many open source applications provided by the MacPorts Project. If you don’t have MacPorts set up already follow the instructions on http://www.macports.org/install.php to install it.

With MacPorts installed, all you need to do is run the following command to get a readline library on your system:-

sudo /opt/local/bin/port install readline

Build from source

You can download the latest source bundle from the GNU readline home page. Uncompress the file and then run the normal ./configure, make and make install process from the top level directory (you’ll need root permissions for the make install part).

With some combinations of OS X and C Compiler versions, configure doesn’t set the correct options for the linker. In these cases you may encounter the following error:-

gcc version 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)
i686-apple-darwin11-llvm-gcc-4.2: -compatibility_version only allowed with -dynamiclib
make[1]: *** [libreadline.6.2.dylib] Error 1

The quickest way to resolve this is to edit shlib/Makefile and change the following line:-

SHOBJ_LDFLAGS = -dynamic

To:-

SHOBJ_LDFLAGS = -dynamiclib

Then run the make command again.

Leave a Reply

Your email address will not be published. Required fields are marked *