views:

317

answers:

3

Hi, I'm trying to build and install readline on a i386 MacBook with Snow Leopard.

I have made the following steps:

download and extract readline-6.0.tar.gz
./configure
make everything
sudo make install

I checked the examples and they appear to work (for instance rltest has support for history). This is the output of file libreadline.6.0.dylib :

libreadline.6.0.dylib: Mach-O 64-bit dynamically linked shared library x86_64

I expected it to be i386 instead, but then if the examples work...

then I have installed the readline package from cabal with the following:

cabal install readline --reinstall --configure-option=--with-readline-includes="/usr/local/include" --configure-option=--with-readline-libraries="/usr/local/lib"

It appears to work: note that without the configure-options installation fails. I have used the --reinstall flag to force reinstallation since I have already made many trials.

This is the output of cabal info:

$ cabal info readline
* readline         (library)
    Synopsis:      An interface to the GNU readline library
    Latest version available: 1.0.1.0
    Latest version installed: 1.0.1.0
    Homepage:      [ Not specified ]
    Bug reports:   [ Not specified ]
    Description:   More information on readline can be found at
                   http:\/\/www.gnu.org\/directory\/readline.html.
    License:       GPL
    Maintainer:    [email protected]
    Source repo:   [ Not specified ]
    Flags:         split-base
    Dependencies:  base >=3, process -any, base <3
    Documentation: [ Not installed ]
    Cached:        Yes
    Modules:
        System.Console.Readline
        System.Console.SimpleLineEditor

Ok, it seems that I am done. No, I am not:

GHCi, version 6.10.4: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
Prelude> import System.Console.Readline
Prelude System.Console.Readline> do { readline "Prompt" }
Loading package syb ... linking ... done.
Loading package base-3.0.3.1 ... linking ... done.
Loading package filepath-1.1.0.2 ... linking ... done.
Loading package old-locale-1.0.0.1 ... linking ... done.
Loading package old-time-1.0.0.2 ... linking ... done.
Loading package unix-2.3.2.0 ... linking ... done.
Loading package directory-1.0.0.3 ... linking ... done.
Loading package process-1.0.1.1 ... linking ... done.
Loading package readline-1.0.1.0 ... linking ... <interactive>: 
/Users/macbook/.cabal/lib/readline-1.0.1.0/ghc-6.10.4/HSreadline-1.0.1.0.o: unknown symbol `_rl_basic_quote_characters'
ghc: unable to load package `readline-1.0.1.0'

Unsuprisingly, I am also unable to build packages which depend on readline (eg JHC).

Can you point me in the right direction? Tell me if you need other info.

Thanks in advance.

+1  A: 

Trying to work with external libraries is one of the biggest pain points in Haskell right now. The community is working on it, but the reality is that most Haskell programmers are students and professors, and maintaining robust installation procedures between the various Unices, Macs, and Windows boxes is the kind of grunt work where you really need a corporation with money on the line in order to get results. (Think Sun with Java...)

Having felt the pain enough times with GTK and OpenGL, I'm rapidly reaching the conclusion that the most pleasant way to work with Haskell is to stick to Linux. I can avoid ninety percent of the pain if I simply boot into Ubuntu.

That said, you may get a more informative error if you try the follwing:

ghc --make TestReadline.hs

Where TestReadline.hs simply tests the presence of the library, like you're doing now with GHCi:

main = do { readline "Prompt" }

There are also a few flags you may want to add to readline's .cabal file that may help you out: extra-libraries, extra-ghci-libraries, and ld-options. Here is some pretty terse documentation. You may find better through Google.

If all else fails, Haskell's IRC channel is very helpful.

But really, is there any reason why Haskell's standard IO doesn't work for you? You know, something like this (cribbed from page 186 of Real World Haskell)?

main = do 
   putStrLn "What's your name?"
   inpStr <- getLine
   putStrLn $ "Welcome, " ++ inpStr ++ "!"
rtperson
To answer your last point: *I* don't need it, JHC requires it :-) I will try ASAP your suggestions and will let you know.
Francesco
Generally, `cabal` provides excellent support for installing external libraries in Haskell - just type `cabal install <library-name>` at a command-line prompt, and it "Just Works". But `readline` on the Mac is problematic, because `editline` libraries on this platform are incorrectly named as if they were `readline` libraries. Please don't generalize from this special case.
Yitz
@Yitz - Thanks for the clarification on the issue with Mac, but on the "Just Works" point, you couldn't be more wrong. Cabal provides excellent support for downloading *bindings* to the underlying libraries, but it does nothing to install those libraries themselves. On Linux, this isn't an issue -- between package managers and standard library locations, getting the libraries is not hard. On Windows, it can be. For example, here's what you need to do to get OpenGL working on Windows: http://netsuperbrain.com/blog/posts/freeglut-windows-hopengl-hglut/ Don't specialize from the general case.
rtperson
@Yitz - P.S., the point of the blog link is not to say that it's impossible to work with bindings to C libraries, just that doing so is nowhere near as frictionless as it is on Linux. And while Cabal is an excellent tool, you may want to follow the conversation on Haskell-Cafe and elsewhere on "Cabal dependency hell." I love Haskell, and its ecosystem improves every month I work with it, but it still has a ways to go, to my mind.
rtperson
+2  A: 

I have found the following procedure which has worked very well for me. I hope it can serve for future reference.

As I suspected, I wasn't correctly compiling readline. The giveaway for this was

1. file explicity told me that the library was 64 bit
2. as per rtperson advice, compiling a test example was illuminating: linking was failing for that.

Look at the output:

ghc --make test_readline.hs 
Linking test_readline ...
ld: warning: in /usr/local/lib/libreadline.dylib, file is not of required architecture

So I set up to compile readline with the correct architecture, it was not guessing correctly. I simply cleaned the build dirs (make distclean), then configured passing the flag -m32 to gcc:

./configure CC="gcc -m32"

and then rebuilt everything (make everything) and installed it (sudo make install). Now the filetype is encouraging:

~ 628 $ file /usr/local/lib/libreadline.dylib 
/usr/local/lib/libreadline.dylib: Mach-O dynamically linked shared library i386

and readline is working, at last.

PS: you can also build the readline-1.0.1.0 package by hand, as detailed on the "Configuring cabal install readline on Snow Leopard with MacPorts" thread in the haskell-cafe mailing list on 29 dec 2009.

Francesco
Congrats! I'm glad I was able to help out, even if only partially.
rtperson
+2  A: 

I, too, ran into this difficulty. It turns out you can compile "fat" binaries, containing both 32- and 64-bit versions, which circumvents this problem very nicely. This is how apple distributes their own libraries, and they tell you how to do it in this technical note:

Building Universal Binaries from "configure"-based Open Source Projects http://developer.apple.com/library/mac/#technotes/tn2005/tn2137.html

The note is a little old -- it pertains to building ppc/i386 binaries -- but the procedure worked fine for me when I substituted "-arch i386 -arch x86_64". I now have, e.g.,

$ file libreadline.a libreadline.a: Mach-O universal binary with 2 architectures libreadline.a (for architecture i386): current ar archive random library libreadline.a (for architecture x86_64): current ar archive random library

Brian
Thanks for the tip and for the link, I didn't know it. +1 from me . I think that it is a good option for distributing a library, but for building a library on one's own box... you should know the architecture :)
Francesco