How to access hs_free_fun_ptr from a Visual Studio DLL

Krasimir Angelov kr.angelov at
Mon Mar 27 02:23:59 EST 2006

Hi Brian,

The problem is that hs_free_fun_ptr is defined in a static library
(the Haskell RTS) while you have declared it with
__declspec(dllimport). In this case the compiler is tring tp optimize
the call and it is using __imp__hs_free_fun_ptr instead of
hs_free_fun_ptr. You have to remove the dllimport pragma and to link
your program with the Haskell RTS library. Unfortunatelly the the
static library format is different for VC++ and GCC and I expect that
you may have problems if you try to statically link gcc code with VC++


2006/3/25, Brian Hulley <brianh at>:
> Hi -
> I have the following declaration and code in part of a DLL I'm writing:
>   extern "C" {
>        typedef void (*HsFunPtr)();
>       extern __declspec(dllimport) void hs_free_fun_ptr(HsFunPtr fp);
>   }
>   enum ECallback { ECallback_Render, ECallback_COUNT};
>   HsFunPtr callback[ECallback_COUNT];
>   void SetCallback(ECallback c, HsFunPtr fp){
>       if (callback[c]){
>          hs_free_fun_ptr(callback[c]);
>      }
>      callback[c] = fp;
>   }
> However when I try to build the DLL, I get the following error from Visual
> Studio:
>   Duma.obj : error LNK2019: unresolved external symbol
> __imp__hs_free_fun_ptr
> So the problem is that the VS is adding __imp__ onto the function name even
> though I've specified it as extern "C" and is moreover just ignoring the
> dllimport directive and complaining that it can't find the function.
> I've also tried deleting the "extern" before the "__declspec" but this
> doesn't make any difference. Also, I've tried putting hs_free_fun_ptr into
> the IMPORTS section of the def file but this doesn't make any difference
> either (I don't even think def files have an IMPORTS section so it's
> probably just being ignored).
> I've got a horrible feeling that VS will need a .lib file for ghc to allow
> it to link against hs_free_fun_ptr but I don't have a clue how to generate
> one...
> Does anyone know how I can get everything to link?
> Thanks, Brian.
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at

More information about the Glasgow-haskell-users mailing list