<div style="font-family: Arial, sans-serif; font-size: 14px; color: rgb(0, 0, 0);">Hi Everyone!</div><div style="font-family: Arial, sans-serif; font-size: 14px; color: rgb(0, 0, 0);"><br></div><div style="font-family: Arial, sans-serif; font-size: 14px; color: rgb(0, 0, 0);">I'm new here, trying to learn the GHC API. using 944 with cabal 3.8.1.0.<br></div><div style="font-family: Arial, sans-serif; font-size: 14px; color: rgb(0, 0, 0);"><br></div><div style="font-family: Arial, sans-serif; font-size: 14px; color: rgb(0, 0, 0);">How do I correctly set a GHC Session's DynFlags (and/or other properties) to ensure local libraries imported by the main target are resolved properly at compile time?</div><div style="font-family: Arial, sans-serif; font-size: 14px; color: rgb(0, 0, 0);"><br></div><div style="font-family: Arial, sans-serif; font-size: 14px; color: rgb(0, 0, 0);">What flags need to be set so that GHC is able to load/analyze/compile all relevant Libraries in a package?</div><div style="font-family: Arial, sans-serif; font-size: 14px; color: rgb(0, 0, 0);"><br></div><div style="font-family: Arial, sans-serif; font-size: 14px; color: rgb(0, 0, 0);">This is my current code:</div><div style="font-family: Arial, sans-serif; font-size: 14px; color: rgb(0, 0, 0);"><br></div><div style="font-family: Arial, sans-serif; font-size: 14px; color: rgb(0, 0, 0);"><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;">withPath :: FilePath -> IO ()</span><div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;">withPath target = do</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> let targetDir = takeDirectory target </span></div></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> let targetFile = takeFileName target</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> listing <- listDirectory targetDir</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> let imports = filter (\f -> takeExtension f == ".hs") listing</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> print imports</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> let moduleName = mkModuleName targetFile</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> g <- defaultErrorHandler defaultFatalMessager defaultFlushOut</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> $ runGhc (Just libdir) $ do</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> initGhcMonad (Just libdir)</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> dynflags <- getSessionDynFlags</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> setSessionDynFlags $ dynflags { ghcLink = LinkInMemory</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> , ghcMode = CompManager</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> , backend = Interpreter</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> , mainModuleNameIs = moduleName</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> , workingDirectory = Just targetDir </span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> , importPaths = [targetDir] ++ importPaths dynflags</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> }</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> </span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> targets <- mapM (\t -> guessTarget t Nothing Nothing) imports</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> setTargets targets</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> setContext [ IIDecl $ simpleImportDecl (mkModuleName "Prelude") ]</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> load LoadAllTargets</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> liftIO . print . ppr =<< getTargets</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> getModuleGraph</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> putStrLn "Here we go!"</span></div><div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> print $ ppr $ mgModSummaries g</span></div><span style="font-family: Menlo, Consolas, Courier New, monospace; font-size: 9pt; line-height: normal;"> putStrLn "☝️ "</span><br></div><div style="font-family: Arial; font-size: 14px;"><br></div><div style="font-family: Arial; font-size: 14px;">However, when I run it (passing to example/app/Main.hs, in which directory are Lib.hs and Lib2.hs, the latter being imported into Main), I get: <br></div><div style="font-family: Arial; font-size: 14px;"><br></div><div style="font-family: Arial; font-size: 14px;"><span style="font-family:monospace"><span style="font-weight: bold; color: rgb(84, 255, 84); background-color: rgb(255, 255, 255); font-size: 9pt; line-height: normal;">$</span><span style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-size: 9pt; line-height: normal;"> cabal run cli -- example/app/Main.hs
</span><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;">Up to date
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;">["Main.hs","Lib.hs","Lib2.hs"]
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;">[main:Main.hs, main:Lib.hs, main:Lib2.hs]
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;">Here we go!
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;">[ModSummary {
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;"> ms_hs_hash = 23f9c4415bad851a1e36db9d813f34be
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;"> ms_mod = Lib,
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;"> unit = main
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;"> ms_textual_imps = [(, Prelude)]
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;"> ms_srcimps = []
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;"> },
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;"> ModSummary {
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;"> ms_hs_hash = e1eccc23af49f3498a5a9566e63abefd
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;"> ms_mod = Lib2,
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;"> unit = main
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;"> ms_textual_imps = [(, Prelude)]
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;"> ms_srcimps = []
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;"> },
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;"> ModSummary {
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;"> ms_hs_hash = 5f6751d7f0d5547a1bdf39af84f8c07f
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;"> ms_mod = Main,
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;"> unit = main
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;"> ms_textual_imps = [(, Prelude), (, Lib2)]
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;"> ms_srcimps = []
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;"> }]
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;">☝ </span><span style="font-family:monospace"><br><br><span style="font-weight: bold; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-size: 9pt; line-height: normal;">example/app/Main.hs:4:1: </span><span style="font-weight: bold; color: rgb(255, 84, 84); background-color: rgb(255, 255, 255); font-size: 9pt; line-height: normal;">error:</span><span style="color:#000000;background-color:#ffffff"></span><br><span style="font-weight: bold; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-size: 9pt; line-height: normal;"> Could not find module ‘Lib2’</span><span style="color:#000000;background-color:#ffffff"></span><br><span style="font-weight: bold; color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-size: 9pt; line-height: normal;"> Use -v (or `:set -v` in ghci) to see a list of the files searched for.</span><span style="color:#000000;background-color:#ffffff"></span><br><span style="font-weight: bold; color: rgb(84, 84, 255); background-color: rgb(255, 255, 255); font-size: 9pt; line-height: normal;"> |</span><span style="color:#000000;background-color:#ffffff"></span><br><span style="font-weight: bold; color: rgb(84, 84, 255); background-color: rgb(255, 255, 255); font-size: 9pt; line-height: normal;">4 |</span><span style="color: rgb(0, 0, 0); background-color: rgb(255, 255, 255); font-size: 9pt; line-height: normal;"> </span><span style="font-weight: bold; color: rgb(255, 84, 84); background-color: rgb(255, 255, 255); font-size: 9pt; line-height: normal;">import qualified Lib2 as L2</span><span style="color:#000000;background-color:#ffffff"></span><br><span style="font-weight: bold; color: rgb(84, 84, 255); background-color: rgb(255, 255, 255); font-size: 9pt; line-height: normal;"> |</span><span style="font-weight: bold; color: rgb(255, 84, 84); background-color: rgb(255, 255, 255); font-size: 9pt; line-height: normal;"> ^^^^^^^^^^^^^^^^^^^^^^^^^^^</span><span style="color:#000000;background-color:#ffffff"></span><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;">cli: example/app/Main.hs:4:1: error:
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;"> Could not find module `Lib2'
</span><span style="font-family:monospace"><br></span><span style="font-family: monospace; font-size: 9pt; line-height: normal;"> Use -v (or `:set -v` in ghci) to see a list of the files searched for.
</span><span style="font-family:monospace"><br><br></span><span style="font-family: Arial, sans-serif;"></span><span style="font-family: Arial, sans-serif;">What do I need to do differently to make this work?</span></div><div style="font-family: Arial; font-size: 14px;"><span style="font-family: Arial, sans-serif;"><br></span></div><div style="font-family: Arial; font-size: 14px;"><span style="font-family: Arial, sans-serif;">I have a local Cabal file I could use, but to know what I need out of it, I need to understand the minimum required info to get this to work. TIA!<br></span></div><div style="font-family: Arial; font-size: 14px;"><span style="font-family: Arial, sans-serif;"><br></span></div><div style="font-family: Arial; font-size: 14px;"><span style="font-family: Arial, sans-serif;">Sincerely,</span></div><div style="font-family: Arial; font-size: 14px;"><span style="font-family: Arial, sans-serif;"><br></span></div><div style="font-family: Arial; font-size: 14px;"><span style="font-family: Arial, sans-serif;">Bob</span></div><div style="font-family: Arial; font-size: 14px;"><span style="font-family: Arial, sans-serif;"><br></span></div>
<div style="font-family: Arial; font-size: 14px;" class="protonmail_signature_block">
<div class="protonmail_signature_block-user protonmail_signature_block-empty">
</div>
<div class="protonmail_signature_block-proton">
Sent with <a rel="noreferrer nofollow noopener" href="https://proton.me/" target="_blank">Proton Mail</a> secure email.
</div>
</div>