user2407038
user2407038

Reputation: 14598

Unable to link FFI library in Haskell

I have the following source file (sdl.hs):

module Main where

import Graphics.UI.SDL.Mixer.Music
import Graphics.UI.SDL.Mixer
import Graphics.UI.SDL

main = loadMUS "" 

I try the following:

ghc --make sdl.hs
C:\Program Files (x86)\Haskell\SDL-mixer-0.6.1\ghc-7.6.3/libHSSDL-mixer-0.6.1.a(Music.o):fake:(.text+0x10): undefined reference to `Mix_FreeMusic' 
...

It gives me a few dozen of these errors. I have tried everything I could (update, clean install, and Google) but I know next to nothing about FFI in Haskell and how it is supposed to work.

Some extra info:

c:\>gcc --version
realgcc.exe (GCC) 4.5.2
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

c:\>ghc --version
The Glorious Glasgow Haskell Compilation System, version 7.6.3

c:\>cabal install sdl sdl-mixer
Resolving dependencies...
All the requested packages are already installed:
SDL-0.6.4
SDL-mixer-0.6.1
Use --reinstall if you want to reinstall anyway.

Attempting to start anything SDL related from GHCi gives the following:

Prelude> import Graphics.UI.SDL.Mixer.Music
Prelude Graphics.UI.SDL.Mixer.Music> loadMUS ""
Loading package SDL-0.6.4 ... <interactive>: Unknown PEi386 section name `.idata$4' (while processing: C:\sdl\SDL-1.2.15\lib\libSDL.dll.a)
ghc.exe: panic! (the 'impossible' happened)
  (GHC version 7.6.3 for i386-unknown-mingw32):
        loadArchive "C:\\sdl\\SDL-1.2.15\\lib\\libSDL.dll.a": failed

Please report this as a GHC bug:  http://www.haskell.org/ghc/reportabug

I found this which seems related but it has been around for a while now and there is no hope in sight of windows getting the proposed `fix'.

Upvotes: 2

Views: 559

Answers (1)

Irene Knapp
Irene Knapp

Reputation: 145

You should be using Cabal, rather than invoking GHC directly, as it streamlines these things a bit more. But that's out of scope here. :)

The solution to this particular issue is generally to list the C libraries on the GHC command line, as in:

ghc --make -lSDL -lSDL_mixer sdl.hs

I don't use Windows (or dynamic linking with GHC), so I don't know if this command works; it's just a thought.

Upvotes: 2

Related Questions