Alex
Alex

Reputation: 44709

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
    import 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?

Upvotes: 3

Views: 958

Answers (2)

C. A. McCann
C. A. McCann

Reputation: 77374

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.

Upvotes: 6

Don Stewart
Don Stewart

Reputation: 137947

Add --make, which includes the linking phase.

Upvotes: 3

Related Questions