[Haskell-cafe] GHCI & Curl under Windows

John Lask jvlask at hotmail.com
Wed Jun 3 22:57:45 EDT 2009

The issue you are experiencing is the result of ghci not using import
libraries to resolve external symbols. Just a bit of explanation for
reference, which will also help you understand the solution to your problem.

Take for example the function declared as

    int myexport(int x){...}

when creating a dll the exported definitions will be included in the dll,
if your using mingw to create the dll, as


 or, if your using ms visual c:


The import libraries (.a,.lib) will contain


in the case of mingw .a lib, and also .lib for ms visual c. These
entries enable the compiler to resolve the linkage.

A client of the library will, generally speaking, have the following 

__declspec(dllimport) int myexport(int x);

the object file created will reference __imp__myexport
obviously if you have an object file with __imp__myexport
and no import file you will not be able to resolve __imp__myexport to 
_myexport (or myexport) in the dll
and ghci does not use import libraries but just searches for the symbols 
defined directly. It
would be nice if ghci could directly resolve symbols decorated like __imp__ 

what to do? Notice that the import libraries (for compilation) contain both 
_myexport and __imp__myexport, therefore if you can get the haskell modules 
to reference the _myexport
rather than __imp__myexport all will be ok both for ghci and also ghc 

so how did the __imp__ get there in the first place?
notice the curl has the cabal option via-C, consequently the curl headers 
will be
read in ...

#if (defined(WIN32) || defined(_WIN32)) && !defined(CURL_STATICLIB)
#define CURL_EXTERN  __declspec(dllimport)

i.e. by default curls sais link me to the dynamic library, if in the
cabal file you define an option

  cc-options:     -DCURL_STATICLIB

then the
but retain the link to the dynamic library

  Extra-libraries: curl

where libcurl is the name of the dynamic import library ie libcurl.a (you 
need to rename libcurl.dll.a, libcurldll.a
or whatever your import is called) as it needs to match the dll name as 
otherwise ghci will not find it eg libcurl.dll

and that's it - all should work fine now!


on my system I like to have both the static import and the dynamic import 
which are named

libcurl.a (static)
libcurl.dll.a (dynamic import)

to make this work with both GHC and GHCI you need to do the following

cabal ...

  Extra-libraries: curl.dll
  -- reference the dynamic import library, whatever name you have

after building the package and installing (your versions will be different)

 ghc-pkg unregister curl-

edit the dist\installed-pkg-config and add
"extra-ghci-libraries: libcurl", or whatever the name of your .dll file is.
Then run

 ghc-pkg update dist\installed-pkg-config

what this will do, is tell ghci the dll name to search for, rather
than relying on the name that you have specified with "Extra-libraries: 
the benefit of this process is that it will enable you to leave the names
of your import libraries and dll files for curl untouched, which
could otherwise break other dependencies you may have.

The long and the short of it is --- much work still needs to be
done to ensure that building and maintaining packages on windows
platforms via cabal and ghc is painless - so far every
package I have used that relied on external libraries has required
some tweaking (and not just setting library paths).

----- Original Message ----- 
From: "Sigbjorn Finne" <sigbjorn.finne at gmail.com>
To: "Martin Huschenbett" <huschi at gmx.org>
Cc: "haskell" <haskell-cafe at haskell.org>
Sent: Thursday, June 04, 2009 12:59 AM
Subject: Re: [Haskell-cafe] GHCI & Curl under Windows

> On Wed, 03 Jun 2009 05:27:53 -0700, Martin Huschenbett <huschi at gmx.org> 
> wrote:
>> Hi Haskellers,
>> I've installed the newest Haskell Platform under Vista and downloaded a 
>> pre compiled version of curl-7.19.4 for MinGW. After changing the build 
>> type in curl.cabal to Simple and supplying the needed paths I could even 
>> build and install curl for haskell.
>> If I write a program using curl and compile it with GHC everything works 
>> fine. But if I try to execute the main function of my program in GHCI I 
>> always get the following error message:
>> Loading package curl-1.3.5 ... linking ... <interactive>: 
>> C:\Devel\Haskell\curl-1.3.5\ghc-6.10.3\HScurl-1.3.5.o: unknown symbol 
>> `__imp__curl_easy_getinfo': unable to load package `curl-1.3.5'
>> Did anybody have the same problem and knows how to fix it?
> Hi Martin,
> perhaps you already have, but did you go through this writeup
>   http://haskell.forkio.com/Home/curl-win32
> and see if there are useful pointers there that might help?
> --sigbjorn
> -- 
> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

More information about the Haskell-Cafe mailing list