Getting Cabal to run on Mac OS X Leopard

In preparation for the work on my Haskell NXT Library, I needed to install Yampa today. The official page lists version 0.9.1 as most recent, though that release is from 2002. Newer (though kinda "inofficial") versions are available through Hackage/Cabal. Getting Cabal to work wasn't difficult at all in the end, but scraping together all the information on how to get there was a bit tricky for an absolute n00b like me. I publish my steps here so that others trying to get Cabal to run on Leopard (or other systems) can save some time.

First, you should have GHC installed via MacPorts (sudo port install ghc)

I installed darcs too, but I don't even think that was necessary (sudo port install darcs)

Now, the most recent Cabal Library (the one included in MacPorts GHC was a bit outdated):
Go to http://haskell.org/cabal/, download and untar the most recent Cabal (library) and cabal-install (commandline interface) packages. Install Cabal as root, as described in the readme-file:

ghc --make Setup.hs
./Setup configure
./Setup build
sudo ./Setup install

For cabal-install to compile, we need to further libraries, HTTP and zlib, both obtainable in the HackageDB (just follow the links). Download and untar, then proceed as with Cabal:

ghc --make Setup.lhs (.lhs in case of HTTP, zlib uses the .hs extension)
./Setup configure
./Setup build
sudo ./Setup install

Finally change to the cabal-install directory and repeat these steps again.

After cabal-install is installed, run cabal update to obtain the latest package list. Now you can install packages via cabal install <package name>

15 Responses to “Getting Cabal to run on Mac OS X Leopard”

  1. […] by loggerheadz on January 27, 2009 Thanks for this Jan, it has saved me lots of […]

  2. hal says:

    yeah, thanks a bunch, helped me alot

  3. […] little gotcha I ran into after following Jan Varwig’s tutorial on installing Cabal & friends on Mac OS X and then subsequently trying to install […]

  4. Eric Wright says:

    When trying to install zlib, I get this error:

    $ sudo ./Setup build
    Preprocessing library zlib-0.5.0.0…
    ld: library not found for -lgmp
    collect2: ld returned 1 exit status
    linking dist/build/Codec/Compression/Zlib/Stream_hsc_make.o failed
    command was: /usr/bin/gcc -lz -L/sw/lib/ghc-6.8.3/lib/bytestring-0.9.0.1.1 -L/sw/lib/ghc-6.8.3/lib/array-0.1.0.0 -L/sw/lib/ghc-6.8.3/lib/base-3.0.2.0 -L/sw/lib/ghc-6.8.3 -lm -lgmp -ldl dist/build/Codec/Compression/Zlib/Stream_hsc_make.o -o dist/build/Codec/Compression/Zlib/Stream_hsc_make

    Do you know what ” -lgmp” means, or what I should look for?

  5. Jan says:

    Your system is missing the library gmp (libgmp.a, the GNU multiprecision library). Install it via your system’s package manager or manually (use Google).

    Then the build should succeed.

  6. Eric Wright says:

    I installed gmp through fink…

    $ fink list -i gmp
    i gmp 4.2.4-1000 GNU multiple precision arithmetic library
    i gmp-shlibs 4.2.4-1000 Shared library for gmp package
    i libgmpxx-shlibs 4.2.4-1000 Shared C++ library for gmp package

    $ ls /sw/lib/libgmp*
    /sw/lib/libgmp.3.4.4.dylib /sw/lib/libgmpxx.4.0.4.dylib
    /sw/lib/libgmp.3.dylib /sw/lib/libgmpxx.4.dylib
    /sw/lib/libgmp.a /sw/lib/libgmpxx.a
    /sw/lib/libgmp.dylib /sw/lib/libgmpxx.dylib
    /sw/lib/libgmp.la /sw/lib/libgmpxx.la

    But I’m getting the same error. Could it be that gcc is called from /usr/bin? Do I need to tell the compiler how to use -lgmp somehow?

    (thanks for the feedback)

  7. Jan says:

    Try adding a -L/sw/lib option somewhere. That should tell the compiler to search that directory for libs too. But I’m really not an expert on neither gcc nor Haskell, far from it.

  8. Eric Wright says:

    Yeah, me neither. Thanks for the suggestions.

  9. Eric Wright says:

    There’s probably a more proper way to do this, but here’s what worked. I created a bash script with this in it:

    !/bin/sh

    export LIBRARY_PATH=/sw/lib:$LIBRARY_PATH
    ./Setup build

    And then I ran

    $ sudo ./script.sh

    That compiled zlib without complaining! Unfortunately cabal-install is still giving me the error:

    $ ./Setup configure
    Configuring cabal-install-0.6.2…
    Setup: At least the following dependencies are missing:
    zlib >=0.4 && <0.6

    And as far as I can tell, I just compiled zlib! Ugh.

  10. Eric Wright says:

    Okay, now I tried running the cabal-install ./bootstrap.sh, and that installed everything as expected.

  11. Duncan Mortimer says:

    Hi, thanks for these instructions.

    Everything seems to work fine, but when I run cabal update I get the following error:

    wlan-n124-20:Desktop dmorti$ cabal update
    Config file /Users/dmorti/.cabal/config not found.
    Writing default configuration to /Users/dmorti/.cabal/config
    Downloading the latest package list from hackage.haskell.org
    cabal: user error (Codec.Compression.Zlib: premature end of compressed stream)

    Any idea what’s going on here? I found some mention of this problem occurring for windows users, but nothing about OSX…??

    cheers!

  12. Adam Wyner says:

    Thanks for this instruction. Before I try this experiment a question – is this also going to work on Snow Leopard, the OS on the Mac after Leopard. I suspect not…. Cheers!

  13. Jan says:

    Honestly, I have no idea but why wouldn’t it work?
    Maybe you have to set an ARCHFLAG= x86_64 before compiling.

  14. Isaac says:

    Hi, I am no computer software developer but I really want to play Cabal on Mac OS. I have OS X Lion. Just wondering if you can reiterate the steps in “English” terms to aid me. Cheers

  15. Jan says:

    This article is about Cabal, the Haskell Package manager. It has nothing to do with Cabal, the Game. From the looks of it the game you meant does not run on Mac OS.

Leave a Reply