The Secret Diary of Han, Aged 0x29

Building readline 5.2 on OS X Leopard

Readline 5.2 does not build properly on OS X Leopard. It fails with a  -compatibility_version only allowed with -dynamiclib error. I ran into this problem when trying to build ruby, using GNU readline instead of the default editline. The problem is easily fixed though. Readline explicitly checks for the darwin version, but does not include 9 (Leopard) in this check. Patch support/shobj-conf using the following:

 --- support/shobj-conf	2007-12-26 18:30:46.000000000 +0900
+++ support/	2007-12-26 18:30:39.000000000 +0900
@@ -142,7 +142,7 @@

# Darwin/MacOS X

@@ -171,7 +171,7 @@

case "${host_os}" in
-	darwin[78]*)	SHOBJ_LDFLAGS=''
+	darwin[789]*)	SHOBJ_LDFLAGS=''
SHLIB_XLDFLAGS='-dynamiclib -arch_only `/usr/bin/arch` -install_name $(libdir)/$@ -current_version $(SHLIB_MAJOR)$(SHLIB_MINOR) -compatibility_version $(SHLIB_MAJOR) -v'
*)		SHOBJ_LDFLAGS='-dynamic'

and rerun configure and make.


Written by Han

December 26, 2007 at 18:29

Posted in Uncategorized

Tagged with

18 Responses

Subscribe to comments with RSS.

  1. Than you, it worked well.


    January 4, 2008 at 06:09

  2. Perfect. Thanks a bunch!


    January 12, 2008 at 07:30

  3. I’m not sure why, but I got this error:
    /tmp/readline-5.2> patch -p0 < leopard.patch
    patching file support/shobj-conf
    patch: **** malformed patch at line 4: ;;

    I’m no patch(1) wizard, so maybe I missed an incantation. I got around it by just editing the file per the patch, though.

    Very helpful anyway, though. Thanks!


    March 26, 2008 at 13:00

  4. Perfect. Thank you.

    Andy Stewart

    May 6, 2008 at 22:00

  5. Firstly – thanks for the patch – it enabled me to build readline on OS X 10.5.2.

    But I still can’t build ruby 1.9! Breaks on ‘compiling readline’:

    readline.c: In function ‘filename_completion_proc_call’:
    readline.c:670: error: ‘filename_completion_function’ undeclared (first use in this function)
    readline.c:670: error: (Each undeclared identifier is reported only once
    readline.c:670: error: for each function it appears in.)
    readline.c:670: warning: assignment makes pointer from integer without a cast
    readline.c: In function ‘username_completion_proc_call’:
    readline.c:695: error: ‘username_completion_function’ undeclared (first use in this function)
    readline.c:695: warning: assignment makes pointer from integer without a cast
    make[1]: *** [readline.o] Error 1
    make: *** [all] Error 1

    Surely someone must’ve got past this by now? I’ve done so much googling, but have turned up nothing that works…

    James Frost

    May 21, 2008 at 07:48

  6. @James: Make sure to point to the right readline when building Ruby 1.9, like so:

    ./configure –prefix=/usr/local/ruby1.9 –with-readline-dir=/usr/local


    May 22, 2008 at 16:49

  7. […] June 28, 2008 by rubyopals Problems installing Gnu readline 5.2 on OS X Leopard. Good explanation. […]

  8. Hi,
    first of all, many thanks to Han for the brilliant hints. Although, even after applying all of them, I still received the same problem with Ruby 1.8.7p22 and 1.9.0 (but not with 1.8.6p120). Here is what finally did the job for me (using Leopard):
    1) Download readline 5.2
    2) Download all patches for readline 5.2 (currently 12 patches are available)
    3) apply all patches
    4) ./configure, make and sudo make install for patched readline [no parameters for my installation]
    5) download Ruby 1.8.7 or 1.9.0
    6) run ./configure –with-readline-dir=/usr/local
    7) run make and sudo make install
    I’m not sure where the differences are compared to Han’s recipe (I’m not very experienced experienced on compiler/make level). But it worked…

    Hans-Uwe Brackel

    July 7, 2008 at 04:08

  9. The latest patch for the current version (at is substantially the same as what Han provides above. It patches the OS check for Leopard (and a few other systems).

    So if the one given here doesn’t work, that’s the next step.

    Matthew Smillie

    July 7, 2008 at 10:31

  10. Thanks, it worked.


    July 30, 2008 at 11:32

  11. Can someone provide more explicit directions on how to apply patch #12?

    I was able to apply the GNU patches 1-11 without any troubles, but with #12, there was an error:

    ~/Desktop/Downloads/readline-5.2 $patch < /Users/Eric/Desktop/patches/readline52-001.txt
    patching file display.c
    ~/Desktop/Downloads/readline-5.2 $patch < /Users/Eric/Desktop/patches/readline52-002.txt
    patching file display.c
    ~/Desktop/Downloads/readline-5.2 $patch < /Users/Eric/Desktop/patches/readline52-003.txt
    patching file display.c
    ~/Desktop/Downloads/readline-5.2 $patch < /Users/Eric/Desktop/patches/readline52-004.txt
    patching file display.c
    ~/Desktop/Downloads/readline-5.2 $patch < /Users/Eric/Desktop/patches/readline52-005.txt
    patching file complete.c
    patching file input.c
    patching file isearch.c
    patching file misc.c
    patching file readline.c
    patching file text.c
    patching file vi_mode.c
    ~/Desktop/Downloads/readline-5.2 $patch < /Users/Eric/Desktop/patches/readline52-006.txt
    patching file display.c
    ~/Desktop/Downloads/readline-5.2 $patch < /Users/Eric/Desktop/patches/readline52-007.txt
    patching file input.c
    ~/Desktop/Downloads/readline-5.2 $patch < /Users/Eric/Desktop/patches/readline52-008.txt
    patching file display.c
    ~/Desktop/Downloads/readline-5.2 $patch < /Users/Eric/Desktop/patches/readline52-009.txt
    patching file display.c
    ~/Desktop/Downloads/readline-5.2 $patch < /Users/Eric/Desktop/patches/readline52-010.txt
    patching file display.c
    Hunk #1 succeeded at 1623 (offset 4 lines).
    ~/Desktop/Downloads/readline-5.2 $patch < /Users/Eric/Desktop/patches/readline52-011.txt
    patching file input.c
    ~/Desktop/Downloads/readline-5.2 $patch < /Users/Eric/Desktop/patches/readline52-012.txt
    can’t find file to patch at input line 21
    Perhaps you should have used the -p or –strip option?
    The text leading up to this was:
    | =====================
    |Readline-Release: 5.2
    |Patch-ID: readline52-012
    |Bug-Reported-by: Chet Ramey
    |This updates the options required to create shared libraries on several
    |systems, including Mac OS X 10.5 (darwin9.x), FreeBSD, NetBSD, OpenBSD,
    |AIX, and HP/UX.
    |*** ../readline-5.2-patched/support/shobj-conf 2006-04-11 09:15:43.000000000 -0400
    |— support/shobj-conf 2007-12-06 23:46:41.000000000 -0500
    File to patch:


    August 28, 2008 at 03:37

  12. Thanks alot! Worked perfectly!


    August 30, 2008 at 19:59

  13. Worked great for me. With regard to Eric’s question: when it says “File to patch: “, just input “support/shobj-conf”. The patch itself fails to look in the support directory.


    September 6, 2008 at 02:23

  14. […] Building readline 5.2 on OS X Leopard « The Secret Diary of Han, Aged 0×29 A patch needed for readline so it can build as a dynamic lib with Leopard. I need this for building cgdb – the curses debugger frontend for gdb (tags: source osx macosx mac readline gdb cgdb dynamic) […]

  15. Thanks for the tip, this patch worked for me better as your version failed with the latest updates:

    — a/support/shobj-conf
    +++ b/support/shobj-conf
    @@ -142,7 +142,7 @@ freebsd[3-9]*|freebsdelf[3-9]*|freebsdaout[3-9]*|dragonfly*)

    # Darwin/MacOS X

    Attila Babo

    October 6, 2008 at 20:42

  16. […] As it happens, when I compiled Python 2.5 or higher on OS X, it linked to either the OS X readline library or the MacPorts one. Which one I don’t know, but it was definitely hosed. So while the interpreter worked fine, the interpreter shell would crash with a Bus Error. So what I did was compile my own plain vanilla version of readline and installed it to /opt. Of course that didn’t work right away because readline wouldn’t build on OS X Leopard without applying a small patch to a build script. […]

  17. […] Taken verbatim from here […]

  18. Issue the following command on Snow Leopard (10.6) after compiling Python (assumed path = /opt/Python-2.6.3) to add readline support to the new Python install.

    cp /System/Library/Frameworks/Python.framework/Versions/2.6/lib/python2.6/lib-dynload/ /opt/Python-2.6.3/lib/python2.6/site-packages/

    Kamal Gill

    October 3, 2009 at 05:38

Comments are closed.

%d bloggers like this: