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

2006-01-24 Thread Cyril Schmidt
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

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


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

2006-01-24 Thread Brian Hulley

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.


___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


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

2006-01-24 Thread Brian Hulley

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 (0xc07b)

Any ideas?

Thanks, Brian.

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


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

2006-01-24 Thread Brian Hulley

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 (0xc07b)


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. 


___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: ghc and gcc-4

2006-01-24 Thread Johannes Waldmann

 are there known problems with ghc-6.4.* and gcc-4.*?
 It seems that -O2 does not work (on i386),
 as gcc says something like Prologue junk.
 (Suse linux 10.0 comes with gcc-4.?`as default compiler).
 
 There may well be problems, yes.  Have you tried 6.4.1?  Or a STABLE
 snapshot?

Did not help, I get the
same behaviour with ghc-6.4.2.20060121-i386-unknown-linux


-- 
-- Johannes Waldmann -- Tel/Fax (0341) 3076 6479/80 --
 http://www.imn.htwk-leipzig.de/~waldmann/ ---

___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users


Re: ghc and gcc-4

2006-01-24 Thread Simon Marlow

Johannes Waldmann wrote:

are there known problems with ghc-6.4.* and gcc-4.*?
It seems that -O2 does not work (on i386),
as gcc says something like Prologue junk.
(Suse linux 10.0 comes with gcc-4.?`as default compiler).


There may well be problems, yes.  Have you tried 6.4.1?  Or a STABLE
snapshot?



Did not help, I get the
same behaviour with ghc-6.4.2.20060121-i386-unknown-linux


Can you run the offending command with -keep-raw-s-file, and send me the 
resulting .raw_s, please?


Cheers,
Simon
___
Glasgow-haskell-users mailing list
Glasgow-haskell-users@haskell.org
http://www.haskell.org/mailman/listinfo/glasgow-haskell-users