Index syndication
comment syndication

Compiling readline on an OSX 10.5 intel x86_64

January 3, 2009 at 02:33 · Filed under apple, mac, unix

I’m stuck with a whole bunch of problems getting code to compile and co-operate nicely on my new MacBookPro. I’m compiling my own PHP, but it defaults to compiling for the i386 (32bit) architecure, which then fails when Apache2 running in 64bit mode tries to use the 32bit DSO for PHP5. Compiling PHP5 as 64bit then fails linking against the i386 pgsql lib, and so on. I really need everything using the x86_64 architecture. How does this all relate to readline under Leopard?

The problem is the Intel Core2 Duo is a 64bit CPU. Apple supplied apps like Apache2 are compiled as Universal binary AND for 32/64bits. This means there are 4 architectures in the binaries.

lantrix@lexx:~ $ file /usr/sbin/httpd
/usr/sbin/httpd: Mach-O fat file with 4 architectures

When I compile PHP as x86_64 of course it complains that the pgsql libs are also not x86_64, and when I compile postgresql as x86_64, it complains the fink readline library I use is not x86_64. Talk about architectural dependancies! I will need to do another post in depth on the fun had with that whole set of dependancies.

This is how and why I arrived at compiling readline on my Mac 64bit intel under Leopard.

On to the readline problems. I start the compile of readline as x86_64 architecture, and this occurs:

gcc -dynamic -arch x86_64 -bind_at_load -arch_only `/usr/bin/arch` -install_name /usr/local/lib/libreadline.5.2.dylib -current_version 5.2 -compatibility_version 5 -v -o libreadline.5.2.dylib -lncurses
Using built-in specs.
Target: i686-apple-darwin9
Configured with: /var/tmp/gcc/gcc-5465~16/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib --build=i686-apple-darwin9 --with-arch=apple --with-tune=generic --host=i686-apple-darwin9 --target=i686-apple-darwin9
Thread model: posix
gcc version 4.0.1 (Apple Inc. build 5465)
i686-apple-darwin9-gcc-4.0.1: -compatibility_version only allowed with -dynamiclib
make[1]: *** [libreadline.5.2.dylib] Error 1
make: [shared] Error 2 (ignored)

Google is your friend, and MacOSXHints forum user dmacks has an answer why this occurs.

The readline compile scripting is ugly (doesn’t use standard build tools, then fakes it…poorly at times). You need -dynamiclib not -dynamic to compile a shared library on OS X, but this indicates a deeper problem: need to patch support/shobj-conf to know darwin9* as a Darwin/MacOS system if you’re on Leopard (I think readline5.2 only recognizes darwin8*, i.e., Tiger).

Still this is not a fix…. But some further searching and I find a Christopher Rasch on a Watir mailing list who shows how to get around this. Effectivly you need to change the makefile for readlines shlibs to use the -dynamiclib switch when compiling.

This gave me a local x86_64 architecure readline library under Leopard. I was able to successfully compile PostgreSQL as -arch x86_64 against the readline library as well.

lantrix@lexx:/usr/local/src/readline-5.2 $ ls -l /usr/local/lib/libreadline.*
-r-xr-xr-x  1 root  lantrix  272480  3 Jan 02:06 /usr/local/lib/libreadline.5.2.dylib
lrwxr-xr-x  1 root  lantrix      21  3 Jan 02:06 /usr/local/lib/libreadline.5.dylib -> libreadline.5.2.dylib
-rw-r--r--  1 root  lantrix  934864  3 Jan 02:06 /usr/local/lib/libreadline.a
lrwxr-xr-x  1 root  lantrix      21  3 Jan 02:06 /usr/local/lib/libreadline.dylib -> libreadline.5.2.dylib

Do what you will with them :-)

lantrix said,

October 20, 2010 @ 13:53

Readline 6.1 It now correctly uses -dynamiclib in the makefile to compile a shared library on OS X.

Ramiro Jr Franco said,

July 30, 2011 @ 03:59

This trick worked to correct the issue when I encountered it with readline 6.2 on OSX 10.7 ( Lion )

lantrix said,

September 2, 2011 @ 19:22

Cool. I’m glad it still works on Lion. I’ve not had to perform this under 10.7 yet.

Stewart Matheson said,

September 15, 2011 @ 07:56

Great Job!

I can confirm this worked for me with readline6.2 and macosx 10.7.1.

Nate Glenn said,

November 4, 2011 @ 02:09

This solved my problems with readline 6.2 on OSX 7.2, after following these instructions, I was able to get my rails and rubymine environment working correctly.

lantrix said,

January 6, 2012 @ 15:21

That’s cool to know that it still works in latest releases of Lion. Thanks Nate & Stewart!

Willem Bakker said,

February 17, 2012 @ 20:25

I have a Philips voip321 telephone, formerly used for Skype under Windows. Now I switched to the Mac (OS X 10.7) and I want to use this phone in this environment. Can anybody help me to make this work? Thanks in advance,
Willem (Netherlands)

Gil said,

December 4, 2013 @ 22:09

Thanks for sharing this!

How Do You Get A Married Woman To Fall In Love With You said,

May 2, 2015 @ 11:36

How Do You Get A Married Woman To Fall In Love With You

… – And women are and what you have problems with approaching how scorpio woman can attract cancer man you will surely turn their heads, towards you. You have your arms are down by … Compiling readline on an OSX 10.5 intel x86_64 – Tech Debug …

RSS feed for comments on this post · TrackBack URI

Leave a Comment