Hi!
Please take a look here: http://www.haskell.org/haskellwiki/GHC/As_a_library
The examples are not working. Even the simpelst one:

import GHC
import GHC.Paths ( libdir )
import DynFlags ( defaultLogAction )
 
main = 
    defaultErrorHandler defaultLogAction $ do
      runGhc (Just libdir) $ do
        dflags <- getSessionDynFlags
        setSessionDynFlags dflags
        target <- guessTarget "test_main.hs" Nothing
        setTargets [target]
        load LoadAllTargets

throws:

$> ghc -package ghc Main.hs
[1 of 1] Compiling Main             ( Main.hs, Main.o )

Main.hs:6:25:
    Couldn't match type `DynFlags' with `[Char]'
    Expected type: DynFlags.FatalMessager
      Actual type: DynFlags.LogAction
    In the first argument of `defaultErrorHandler', namely
      `defaultLogAction'
    In the expression: defaultErrorHandler defaultLogAction
    In the expression:
      defaultErrorHandler defaultLogAction
      $ do { runGhc (Just libdir)
             $ do { dflags <- getSessionDynFlags;
                    setSessionDynFlags dflags;
                    .... } }

Main.hs:7:7:
    Couldn't match expected type `DynFlags.FlushOut'
                with actual type `IO SuccessFlag'
    In a stmt of a 'do' block:
      runGhc (Just libdir)
      $ do { dflags <- getSessionDynFlags;
             setSessionDynFlags dflags;
             target <- guessTarget "test_main.hs" Nothing;
             setTargets [target];
             .... }
    In the second argument of `($)', namely
      `do { runGhc (Just libdir)
            $ do { dflags <- getSessionDynFlags;
                   setSessionDynFlags dflags;
                   .... } }'
    In the expression:
      defaultErrorHandler defaultLogAction
      $ do { runGhc (Just libdir)
             $ do { dflags <- getSessionDynFlags;
                    setSessionDynFlags dflags;
                    .... } }