diff options
-rw-r--r-- | compiler/ghci/Linker.lhs | 4 | ||||
-rw-r--r-- | compiler/ghci/ObjLink.lhs | 19 |
2 files changed, 18 insertions, 5 deletions
diff --git a/compiler/ghci/Linker.lhs b/compiler/ghci/Linker.lhs index 63c68c5b35..747edde140 100644 --- a/compiler/ghci/Linker.lhs +++ b/compiler/ghci/Linker.lhs @@ -1091,9 +1091,7 @@ searchForLibUsingGcc dflags so dirs = do mkSOName :: FilePath -> FilePath mkSOName root | isDarwinTarget = ("lib" ++ root) <.> "dylib" - | isWindowsTarget = -- Win32 DLLs have no .dll extension here, because - -- addDLL tries both foo.dll and foo.drv - root + | isWindowsTarget = root <.> "dll" | otherwise = ("lib" ++ root) <.> "so" -- Darwin / MacOS X only: load a framework diff --git a/compiler/ghci/ObjLink.lhs b/compiler/ghci/ObjLink.lhs index cd593f7b45..f459145606 100644 --- a/compiler/ghci/ObjLink.lhs +++ b/compiler/ghci/ObjLink.lhs @@ -23,6 +23,7 @@ module ObjLink ( import Panic import BasicTypes ( SuccessFlag, successIf ) import Config ( cLeadingUnderscore ) +import Util import Control.Monad ( when ) import Foreign.C @@ -30,7 +31,7 @@ import Foreign ( nullPtr ) import GHC.Exts ( Ptr(..) ) import GHC.IO.Encoding ( fileSystemEncoding ) import qualified GHC.Foreign as GHC - +import System.FilePath ( dropExtension ) -- --------------------------------------------------------------------------- @@ -62,10 +63,24 @@ prefixUnderscore | cLeadingUnderscore == "YES" = ('_':) | otherwise = id +-- | loadDLL loads a dynamic library using the OS's native linker +-- (i.e. dlopen() on Unix, LoadLibrary() on Windows). It takes either +-- an absolute pathname to the file, or a relative filename +-- (e.g. "libfoo.so" or "foo.dll"). In the latter case, loadDLL +-- searches the standard locations for the appropriate library. +-- loadDLL :: String -> IO (Maybe String) -- Nothing => success -- Just err_msg => failure -loadDLL str = do +loadDLL str0 = do + let + -- On Windows, addDLL takes a filename without an extension, because + -- it tries adding both .dll and .drv. To keep things uniform in the + -- layers above, loadDLL always takes a filename with an extension, and + -- we drop it here on Windows only. + str | isWindowsHost = dropExtension str0 + | otherwise = str0 + -- maybe_errmsg <- withFileCString str $ \dll -> c_addDLL dll if maybe_errmsg == nullPtr then return Nothing |