[Haskell-cafe] Trouble with FFI on Windows2000...

Serge LE HUITOUZE slehuitouze at telisma.com
Sat Dec 20 14:43:54 EST 2008


Hi there!

I'm trying to FFI-bind a MS Visual dll (under Windows2000) to a Haskell program.


I have this little C(++) dll:
******* FILE inc.h: START *******
extern "C" {
  int pten(int i);
}
******* FILE inc.h: END   *******

******* FILE inc.cpp: START *******
#include "inc.h"
int pten(int i) {
  return i+10;
}
******* FILE inc.cpp: END   *******

******* FILE cproj1.def: START *******
LIBRARY cproj1
EXPORTS
pten
******* FILE cproj1.def: END   *******

And this little Haskell program:
******* FILE testFFI_2.hs: START *******
{-# LANGUAGE ForeignFunctionInterface #-}
module Main where
import Foreign.C -- get the C types
foreign import ccall unsafe "pten" c_pten :: CInt -> CInt
plus10 :: Int -> Int
plus10 i = fromIntegral (c_pten (fromIntegral i))
main = print (map plus10 [1..10])
******* FILE testFFI_2.lhs: END   *******

Using information found at paragraph 1.4.3.4 of 
http://www.haskell.org/haskellwiki/GHC:FAQ#GHC_on_Windows
I do the following:
> dlltool -d cproj1.def -l libcproj1.a
> ghc --make testFFI_2.hs -optl-lcproj1 -optl-L.

This seems fine, since it produces a "testFFI_2.exe".
However, executing it, I get a MSWindows error box with a message
that looks like (approximate translation): 
"DLL (null) not found on specified path"

At first, I didn't have the "LIBRARY" directive in the ".def" file,
so I thought that was the reason for the "(null)" appearing in the
message. But adding said directive didn't change anything...

[I've checked that my MSVisual dll was in current dir, and that this
dir was in the search paths showed in the error box]

Can anyone enlighten me?

Thanks in advance.

--Serge


More information about the Haskell-Cafe mailing list