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

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). Cheers Cyril

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: // TestDLL.cpp : Defines the entry point for the DLL application. // #include "stdafx.h" BOOL APIENTRY DllMain( HANDLE hModule, 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: TestDLL.def: LIBRARY TestDLL EXPORTS cfun 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.

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)" Any ideas? Thanks, Brian.

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, Brian.
participants (2)
-
Brian Hulley
-
Cyril Schmidt