[Haskell-cafe] FFI woes!

Sebastian Sylvan sebastian.sylvan at gmail.com
Tue Dec 14 22:09:04 EST 2004

I've been trying to use the C library FMOD in Haskell for about an hour now.

The first test was the simple FSOUND_Init(int,int,uint) function which
I got working by doing the following:
foreign import ccall "fmod.h FSOUND_Init" fsound_Init :: CInt -> CInt
-> CUInt -> IO CChar

Which appeared to work just fine (the call went through, and I got
sensible return values).

Then I wanted to play some music so I tried to bring in the function
FMUSIC_LoadSong which has the following C prototype (copy-pasted from
the API):

const char *name

By doing this in Haskell:

data MusicModule = MusicModule

foreign import ccall "fmod.h FMUSIC_LoadSong" fmusic_LoadSong ::
CString -> IO ForeignPtr MusicModule)

I assume that this is how the ForeignPtr is meant to be used (with a
dummy data type).

Now if I compile this (under windows) with:
ghc -fglasgow-exts --make FMODTest.hs -o test.exe -Llib -Iincludes -lfmod

I get the following error:
    Unacceptable result type in foreign declaration:
        IO (ForeignPtr MusicModule)
    When checking declaration:
        foreign import ccall safe "static fmod.h &FMUSIC_LoadSong" fmusic_LoadSo
ng :: Ptr CChar -> IO (ForeignPtr MusicModule)

That's not a very helpful error message!

Any ideas?


Sebastian Sylvan
UIN: 44640862

More information about the Haskell-Cafe mailing list