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

Simon Peyton-Jones simonpj at
Mon Jan 23 06:26:34 EST 2006

GHC now makes it easy for all users to contribute new documentation
about GHC to help other users, by adding to the GHC documentation wiki.
See the "Collaborative documentation" heading on

Linking to C++ would be an ideal topic.  It's a regular question, and
not one of our strengths at GHC HQ!


| -----Original Message-----
| From: glasgow-haskell-users-bounces at
| bounces at] On Behalf Of Cyril Schmidt
| Sent: 23 January 2006 09:57
| To: glasgow-haskell-users at
| Subject: Re: Linking with C++ produced by Visual Studio .NET on
Windows XP?
| I am far from being an expert, but I have seen no answer to your
| so far, so I'll tell how I'd do it (however ugly that might be). I
| have a sample project, but it should be fairly easy to make it.
| 1. Make a DLL project in Visual Studio. VS will create a .vcproj and
| .sln files for you. Add your C++ source files to this project.
| 2. Create a .def file for your DLL. It might look like
| 	function1
|         function2
| where function1 and function2 are the names of the C++ functions that
| you want to invoke from Haskell (there can be more of them, of
| MyDLL is the name of your DLL.
| 3. Create an import library that can be used by ghc:
| dlltool -d MyDLL.def -l libMyDLL.a
| where MyDLL.def is the name of the .def file, libMyDLL.a is the import
| library.
| 4. Link your Haskell project, adding the library:
| ghc --make main.hs -optl-lMyDLL -optl-L.
| (-optl switch passes its argument as an option to the linker).
| Hope this helps.
| Cheers,
| Cyril
| ___
| >Hi -
| >I'm wondering if anyone has a simple Visual Studio .NET C++ project
| >would demonstrate how to link C++ with Haskell (or vice versa). Ie a
| >.vcproj, .cpp, and .h file containing one C++ function and a Haskell
| >main.hs that calls this function, so that if I click on the .sln file
| >hit F6 the VS project will build then on the command line if I type
| >ghc --make main.hs the Haskell program will be built so that when I
| >"main" on the command line it will run and call the C++ function.
| >Sorry if this all sounds too basic but I don't know how to compile
C++ from
| >the command line at all or how to use make files, and I need to use
| >Visual Studio compiler because my own C++ code relies on Microsoft
| >extensions...

More information about the Glasgow-haskell-users mailing list