Saturday, June 27, 2009

Installing curl from hackage on Cygwin

On a Windows machine, I upgraded to ghc-6.10.3 and was in the process of building and installing libraries from hackageDB, Haskell's CPAN—hmm, or should that be Haskell's CTAN?

I had already upgraded cabal-install:

$ cabal --version
cabal-install version 0.6.2
using version 1.6.0.3 of the Cabal library
I was unsuccessful installing curl from a cmd.exe prompt:
c:\>cabal install curl
Resolving dependencies...
Configuring curl-1.3.5...
cabal: Error: some packages failed to install:
curl-1.3.5 failed during the configure step. The exception was:
sh: runGenProcess: does not exist (No such file or directory)
Fair enough: installing curl requires a real shell, so let's try from inside Cygwin:
$ cabal install curl
Resolving dependencies...
Configuring curl-1.3.5...
checking for gcc... /cygdrive/c/ghc/ghc-6.10.3/gcc
checking for C compiler default output file name... a.exe
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... .exe
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether /cygdrive/c/ghc/ghc-6.10.3/gcc accepts -g... no
checking for /cygdrive/c/ghc/ghc-6.10.3/gcc option to accept ANSI C... none needed
checking how to run the C preprocessor... /cygdrive/c/ghc/ghc-6.10.3/gcc -Bc:/ghc/ghc-6.10.3/gcc-lib -Ic:/ghc/ghc-6.10.3/include/mingw -E
configure: error: curl libraries not found, so curl package cannot be built
See `config.log' for more details.
cabal.exe: Error: some packages failed to install:
curl-1.3.5 failed during the configure step. The exception was:
exit: ExitFailure 1
I already installed Cygwin's curl-devel package, so maybe I needed to help the linker along (note the DOS-ish paths because the mingw gcc bundled with ghc doesn't know about Cygwin):
$ cabal configure \
        --extra-include-dirs=c:/cygwin/usr/include \
        --extra-lib-dirs=c:/cygwin/usr/lib
Same failure as above.

Maybe if I build the package by hand:

$ cd /tmp

$ cabal fetch curl
Resolving dependencies...
No packages need to be fetched. All the requested packages are already cached.

$ cabal unpack curl
Unpacking curl-1.3.5...

$ cd curl-1.3.5/

$ cabal configure --extra-lib-dirs=c:/cygwin/usr/lib --extra-include-dirs=c:/cygwin/usr/include
Resolving dependencies...
Configuring curl-1.3.5...
checking for gcc... gcc
checking for C compiler default output file name... a.exe
checking whether the C compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables... .exe
checking for suffix of object files... o
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking how to run the C preprocessor... gcc -E
configure: creating ./config.status
config.status: creating curl.buildinfo
cabal.exe: Missing dependency on a foreign library:
* Missing C library: curl
This problem can usually be solved by installing the system package that
provides this library (you may need the "-dev" version). If the library is
already installed but in a non-standard location then you can use the flags
--extra-include-dirs= and --extra-lib-dirs= to specify where it is.
No dice.

I tried fiddling with the environment (CC, CFLAGS, LD, and LDFLAGS) and running ./configure by hand, but that produced only frustration.

"If you can't beat 'em, join 'em," I said, and

$ cp /usr/lib/libcurl.a /cygdrive/c/ghc/ghc-6.10.3/gcc-lib/

$ cabal install curl --extra-include-dirs=c:/cygwin/usr/include
[...]
/usr/bin/ar: creating dist\build\libHScurl-1.3.5.a
Installing library in C:\Program Files\Haskell\curl-1.3.5\ghc-6.10.3
Registering curl-1.3.5...
Reading package info from "dist\\installed-pkg-config" ... done.
Writing new package config file... done.
Success!

3 comments:

Max Bolingbroke said...

Actually, your first method will work. However, it is complicated by the fact that /usr/lib is actually stored on the file system at /lib (see HKLM\Software\Cygnus Solutions\Cygwin\mounts v2\/usr/lib).

The upshot of this is that the following command should work:

cabal install curl --extra-include-dirs=c:/cygwin/usr/include
--extra-lib-dirs=c:/cygwin/lib

I've successfully used this method to install Darcs using the Cygwin-provided libz and libcurl.

Greg said...

Max: Much better! Thanks!

Eric Mariacher said...

I had the same issues that you encountered, and the method you proposed did not work for me :(

So I did some kind of hardcopy of dlls, libs and exe as explained in http://eric-mariacher.blogspot.com/2010/03/getting-haskell-xml-toolbox-to-run-on.html
I know it's bad, but it seems to work...