在 OS X 上,我正在尝试为 haskell 的 Cabal 安装 zlib 先决条件。我收到此错误:
$ 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
库 -lgmp 位于 /sw/lib 中,因此如果我手动添加 -L/sw/lib,我可以成功运行该命令(“/usr/bin/gcc ...”)。问题是 sudo 不知道 /sw/lib。看哪:
$ 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
$
如何告诉 sudo 版本的 gcc 在 /sw/lib 中查找库?我是否在 root 的 .bash_profile 上添加环境变量?如果有,是哪一个?
更新: 可能有更合适的方法来做到这一点,但这就是有效的。我在其中创建了一个 bash 脚本:
#!/bin/sh
export LIBRARY_PATH=/sw/lib:$LIBRARY_PATH
./Setup build
然后我跑了
$ sudo ./script.sh
那编译zlib没有抱怨 - 万岁!不幸的是 cabal-install 仍然给我错误:
$ ./Setup configure
Configuring cabal-install-0.6.2…
Setup: At least the following dependencies are missing:
zlib >=0.4 && <0.6
所以我回到了 cabal-install 目录(这是我首先要做的),然后运行......
$ ./bootstrap.sh
...并且按预期安装了所有内容。