From 557d26fabacbbf4e47480feae385f20761e1096f Mon Sep 17 00:00:00 2001 From: Ziyang Liu Date: Fri, 8 Oct 2021 22:25:04 -0700 Subject: Suggest -dynamic-too in failNonStd when applicable I encountered an error that says ``` Cannot load -dynamic objects when GHC is built the normal way To fix this, either: (1) Use -fexternal-interpreter, or (2) Build the program twice: once the normal way, and then with -dynamic using -osuf to set a different object file suffix. ``` Or it could say ``` (2) Use -dynamic-too ``` --- compiler/GHC/Linker/Loader.hs | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'compiler/GHC') diff --git a/compiler/GHC/Linker/Loader.hs b/compiler/GHC/Linker/Loader.hs index ef15615656..3cdee27863 100644 --- a/compiler/GHC/Linker/Loader.hs +++ b/compiler/GHC/Linker/Loader.hs @@ -628,24 +628,38 @@ checkNonStdWay dflags interp srcspan normalObjectSuffix :: String normalObjectSuffix = phaseInputExt StopLn +data Way' = Normal | Prof | Dyn + failNonStd :: DynFlags -> SrcSpan -> IO (Maybe FilePath) failNonStd dflags srcspan = dieWith dflags srcspan $ - text "Cannot load" <+> compWay <+> - text "objects when GHC is built" <+> ghciWay $$ + text "Cannot load" <+> pprWay' compWay <+> + text "objects when GHC is built" <+> pprWay' ghciWay $$ text "To fix this, either:" $$ text " (1) Use -fexternal-interpreter, or" $$ - text " (2) Build the program twice: once" <+> - ghciWay <> text ", and then" $$ - text " with" <+> compWay <+> - text "using -osuf to set a different object file suffix." + buildTwiceMsg where compWay - | ways dflags `hasWay` WayDyn = text "-dynamic" - | ways dflags `hasWay` WayProf = text "-prof" - | otherwise = text "normal" + | ways dflags `hasWay` WayDyn = Dyn + | ways dflags `hasWay` WayProf = Prof + | otherwise = Normal ghciWay - | hostIsDynamic = text "with -dynamic" - | hostIsProfiled = text "with -prof" - | otherwise = text "the normal way" + | hostIsDynamic = Dyn + | hostIsProfiled = Prof + | otherwise = Normal + buildTwiceMsg = case (ghciWay, compWay) of + (Normal, Dyn) -> dynamicTooMsg + (Dyn, Normal) -> dynamicTooMsg + _ -> + text " (2) Build the program twice: once" <+> + pprWay' ghciWay <> text ", and then" $$ + text " " <> pprWay' compWay <+> + text "using -osuf to set a different object file suffix." + dynamicTooMsg = text " (2) Use -dynamic-too," <+> + text "and use -osuf and -dynosuf to set object file suffixes as needed." + pprWay' :: Way' -> SDoc + pprWay' way = text $ case way of + Normal -> "the normal way" + Prof -> "with -prof" + Dyn -> "with -dynamic" getLinkDeps :: HscEnv -> HomePackageTable -> LoaderState -- cgit v1.2.1