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

Brian Hulley brianh at
Tue Jan 24 07:05:33 EST 2006

Brian Hulley wrote:
> Brian Hulley wrote:
>> and compiled with
>> ghc -fglasgow-exts --make Main.hs -optl-lTestDLL -optl-L
> Oops! I see I missed out the "." which I'd not realised was part of
> the command line (seems the linker need to be told explicity to look
> in the current directory also), so it links using:
> ghc -fglasgow-exts --make Main.hs -optl-lTestDLL -optl-L.
> I then copied Debug/TestDLL.dll into the current directory so that it
> is in the same directory as main.exe, but now I get an error when I
> run the application. It finds the dll ok, but then a dialog box pops
> up saying:
> "The application failed to initialize properly (0xc000007b)"

I found the answer. It seemed I didn't declare the C++ function properly. 
The correct function definition is:

extern "C" __declspec(dllexport) int cfun(int x){
       return x * 3;

so that the function name doesn't get mangled and it is exported.

Best regards,

More information about the Glasgow-haskell-users mailing list