Linking to SDL and other libraries in Haskell

How do I tell ghc to tell ld to link compiled binaries to the SDL library?

I have source.hs:

    import Prelude
    import Graphics.UI.SDL as SDL
    import Data.Maybe
    import GHC.Word
    import Control.Applicative
    ...

When I do this:

    ghc source.hs

I get a bunch of related errors like this:

    pong.o: In function `s1Ww_info':
    (.text+0x449): undefined reference to `SDLzm0zi5zi9_GraphicsziUIziSDLziRect_Rect_con_info'

What am I doing wrong?

+3
source share
2 answers

If for some reason you do not want to use the GHC parameter --make, this should work:ghc source.hs -lSDL -package SDL

If you need some of the non-core SDL sub-libraries, you will have to include them separately, for example, ghc source.hs -lSDL -SDL_ttf -package SDL -package SDL-ttf

You can also consider creating an assembly file using cabal, the Haskell packaging system, especially if your program goes beyond several source files.

- , , Haskell SDL, " " Linux - Windows, OS X - , SDL .

+6

--make, .

+3

Source: https://habr.com/ru/post/1726381/


All Articles