GHC API gives a weird error about .hi-boot files

Can anyone tell me what I'm doing wrong with the GHC API? I'm getting the following error message from the GHC API: Can't find interface-file declaration for variable Main.picture Probable cause: bug in .hi-boot file, or inconsistent .hi file Use -ddump-if-trace to get an idea of which file caused the error The source code I'm loading doesn't seem to matter at all, except that it defines a top-level variable called 'picture'. Of course, if I change the module name then I get a different module name in the error, but that's about it. The code I'm using to load the file is as follows: getPicture src = do fn <- chooseFileName ".hs" B.writeFile fn src codeErrors <- newIORef [] GHC.defaultErrorHandler (addErrorTo codeErrors) $ GHC.runGhc (Just GHC.libdir) $ GHC.handleSourceError (handle codeErrors) $ do dflags <- GHC.getSessionDynFlags GHC.setSessionDynFlags $ dflags { GHC.ghcMode = GHC.OneShot, GHC.ghcLink = GHC.LinkInMemory, GHC.hscTarget = GHC.HscInterpreted, GHC.log_action = addErrorTo codeErrors } target <- GHC.guessTarget fn Nothing GHC.setTargets [target] r <- fmap GHC.succeeded (GHC.load GHC.LoadAllTargets) case r of True -> do mods <- GHC.getModuleGraph GHC.setContext [ GHC.ms_mod (head mods) ] [ GHC.simpleImportDecl (GHC.mkModuleName "Graphics.Gloss") ] v <- GHC.compileExpr "picture :: Picture" return (Right (unsafeCoerce# v :: Picture)) False -> return (Left codeErrors) I can't see anything I'm doing obviously wrong here, but I'm not at all familiar with GHC's build process, so I'm hoping someone can pipe up and point out the obvious stuff I've missed. Any ideas? -- Chris Smith

On Mon, 2011-08-15 at 03:34 -0600, Chris Smith wrote:
Can anyone tell me what I'm doing wrong with the GHC API?
Answering my own question: I was passing OneShot as the mode instead of CompManager. I still don't understand why, but random trial and error to the rescue! That solves the problem for now... on to figure out the SafeHaskell extension so I can get this online on a public network. -- Chris Smith
participants (1)
-
Chris Smith