tags:

views:

309

answers:

3

On OS X I'm trying to install the zlib prerequisite for haskell's Cabal. 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

The library -lgmp is found in /sw/lib, so I can run that command ("/usr/bin/gcc ...") successfully if I manually add -L/sw/lib. The problem is that sudo doesn't know about /sw/lib. Behold:

$ gcc -print-search-dirs | grep sw
libraries: =/lib/i686-apple-darwin9/4.0.1/:/lib/:/usr/lib/i686-apple-darwin9/4.0.1/:/usr/lib/:./i686-apple-darwin9/4.0.1/:./:/sw/lib/i686-apple-darwin9/4.0.1/:/sw/lib/:/usr/lib/gcc/i686-apple-darwin9/4.0.1/:/usr/lib/gcc/i686-apple-darwin9/4.0.1/:/usr/lib/gcc/i686-apple-darwin9/4.0.1/../../../../i686-apple-darwin9/lib/i686-apple-darwin9/4.0.1/:/usr/lib/gcc/i686-apple-darwin9/4.0.1/../../../../i686-apple-darwin9/lib/:/usr/lib/gcc/i686-apple-darwin9/4.0.1/../../../i686-apple-darwin9/4.0.1/:/usr/lib/gcc/i686-apple-darwin9/4.0.1/../../../
$ sudo gcc -print-search-dirs | grep sw
$

How do I tell the sudo version of gcc to look in /sw/lib for libraries? Do I add an environment variable on root's .bash_profile? If so, which one?

UPDATE: 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 - hooray! 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

So I went back to the cabal-install dir (which is what I'm trying to do in the first place), and ran...

$  ./bootstrap.sh

...and that installed everything as expected.

A: 

Try setting LDFLAGS=-L/sw/lib.

Ben Alpert
Set it where, specifically? I tried putting it in a previously-nonexistent ~/.bash_profile file for the root user, as well as adding it to my own ~/.bash_profile. Neither makes a difference.
Eric Wright
A: 

GHC now comes with an installer for OS X (Leopard, not sure about Tiger). The only issue is that if you use macports or fink, these will probably not see that you have GHC installed and try to install their own version of it.

nominolo
+1  A: 

Why you use sudo ever? You should not compile as super user. Compile as normal user and install as super user.

Hynek -Pichi- Vychodil