Error Interpreting Main with API

C.M.Brown cmb21 at
Fri Apr 18 15:21:24 EDT 2008


I am trying to use the API to interpret a Main module and get some type
information from it. However, everytime I try to load a "Main.hs" module
using the API I get the following error message:

/usr/local/packages/ghc-6.8.2/lib/ghc-6.8.2/libHSrts.a(Main.o): In
function `real_main':
Main.c:(.text+0x7): undefined reference to `__stginit_ZCMain'
Main.c:(.text+0x36): undefined reference to `ZCMain_main_closure'
collect2: ld returned 1 exit status

If I create an empty file called "Main" within the directory where
"Main.hs" is located the program suceeds, I'm guessing this is because
there is no linking involved. Is there an extra flag I need to pass to GHC
in order to avoid this error? It works perfectly if I try it on a
module that is not called Main.

main =
  defaultErrorHandler defaultDynFlags $
   let packageConf = "/usr/local/packages/ghc-6.8.2/lib/ghc-6.8.2"
   session     <- GHC.newSession {-JustTypecheck-} (Just (filter (/= '\n')
   dflags0 <- getSessionDynFlags session
   (f1,b) <- parseDynamicFlags dflags0 ["-fglasgow-exts"]
   setSessionDynFlags session f1{verbosity=6, hscTarget = HscInterpreted}
   target <- GHC.guessTarget
"/home/cmb21//HaRe_Project/testing/subIntroPattern/Main.hs" Nothing
   GHC.addTarget session target
   GHC.load session GHC.LoadAllTargets
   usermod <- findModule session (mkModuleName "Main") Nothing
   setContext session [usermod] []
   return session

I hope somebody can share some light!
Kind regards,

More information about the Glasgow-haskell-users mailing list