Linking to SDL and other libraries in Haskell
How to tell ghc to tell ld to link compiled binaries to SDL library?
I have a source.hs :
import Prelude
import Graphics.UI.SDL as SDL
import Data.Maybe
impor开发者_JAVA百科t GHC.Word
import Control.Applicative
...
When I do:
ghc source.hs
I get a bunch of linking errors similar to this one:
pong.o: In function `s1Ww_info':
(.text+0x449): undefined reference to `SDLzm0zi5zi9_GraphicsziUIziSDLziRect_Rect_con_info'
What am I doing wrong?
If for some reason you don't want to use GHC's --make
option, this should work: ghc source.hs -lSDL -package SDL
If you want some of the non-core SDL sub-libraries, you'll have to include those separately, e.g., ghc source.hs -lSDL -SDL_ttf -package SDL -package SDL-ttf
You may also want to consider setting up a build file using cabal, the Haskell packaging system, especially if your program expands beyond a couple source files.
And a word of warning--you didn't mention what operating system you're using, but last time I tried Haskell's SDL bindings only worked "out of the box" on Linux--both Windows and OS X cause it problems, due to an ugly hack that SDL uses when starting itself on those platforms.
Add --make
, which includes the linking phase.
精彩评论