Search code examples
haskellcabalcabal-install

Cabal ignores --extra-lib-dirs option in clang invocation


I'm trying to install the byteable package on OS X, but Cabal fails with the error ld: library not found for -lgmp. I do in fact have libgmp installed, but in a nonstandard location, in LOCATION=$HOME/homebrew/lib. (i.e. $LOCATION/libgmp.dylib exists).

I tried using the extra-lib-dirs option, both in my Cabal .config file and also in the command line invocation (i.e. cabal install --extra-lib-dirs="$LOCATION" byteable), but I get the same linker error. When I use the verbose option (--verbose=3), I can see that the call to clang in fact does not include the $LOCATION directory in the -L options.

What do I have to do to get cabal to search additional library directories during package installation?


Solution

  • This is probably not a great solution, but you can add the location of your libgmp to the LIBRARY_PATH environment variable when you execute cabal install.

    In your case, something like:

    LIBRARY_PATH=$HOME/homebrew/lib:$LIBRARY_PATH cabal install <package>

    Or, for the standard Homebrew location:

    LIBRARY_PATH=/usr/local/lib:$LIBRARY_PATH cabal install <package>

    Unfortunately, while I can find documentation on LIBRARY_PATH for gcc, I can't find anything that describes its use for clang. However, the above solution Works For Me (TM) and I am running clang.

    This seems to be something that has broken with Yosemite. I had no problem with cabal install for the Yosemite Beta, which I ran for several months. However, when I did a fresh install of Yosemite, I had the same problem you describe, with clang unable to find libgmp.