Linking with C++ produced by Visual Studio .NET on Windows XP?

Brian Hulley brianh at
Tue Jan 24 06:28:19 EST 2006

Cyril Schmidt wrote:
> Brian Hulley wrote:
>> Thanks. The only problem is that dlltool doesn't work because I don't
>> have
>> cygwin installed.
> dlltool usually comes with the Windows distribution of GHC (at least
> GHC 6.4 and 6.4.1 have it; check gcc-lib directory).

Thanks - I wonder why they didn't put all the binaries in the bin directory?
Anyway, I've added gcc-lib to my path and deleted the version of dlltool.exe 
that I downloaded, but for some reason it won't link. I used the following 
commands (as per your post):

C++ file adapted from default generated by VS DLL project:


// TestDLL.cpp : Defines the entry point for the DLL application.

#include "stdafx.h"
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
    return TRUE;

int __stdcall cfun(int x){
 return x * 3;

I built this with VS, then wrote a def file:



Then I generated the lib using:

dlltool -d TestDLL.def -l libTestDLL.a

Then I wrote a Haskell program Main.hs:

module Main where

import GHC.Exts

foreign import ccall cfun :: Int# -> Int#

main = do
       let a = cfun 10#
       putStrLn $ show $ I# a

and compiled with

ghc -fglasgow-exts --make Main.hs -optl-lTestDLL -optl-L

but I now get an error message:

Linking ...
c:\ghc\ghc-6.4\gcc-lib\ld.exe: cannot find -lTestDLL

Any ideas?

Thanks, Brian.

More information about the Glasgow-haskell-users mailing list