這一計劃將所需的文件複製到指定目錄(僅在Windows上運行):
import Data.List (isSuffixOf)
import System.Environment (getArgs)
import GHC.Paths (libdir)
import System.Directory
import System.FilePath
import System.Cmd
main = do
[to] <- getArgs
let libdir' = to </> "lib"
createDirectoryIfMissing True libdir'
copy libdir libdir'
rawSystem "xcopy"
[ "/e", "/q"
, dropFileName libdir </> "mingw"
, to </> "mingw\\"]
-- | skip some files while copying
uselessFile f
= or $ map (`isSuffixOf` f)
[ "."
, "_debug.a"
, "_p.a", ".p_hi" -- libraries built with profiling
, ".dyn_hi", ".dll"] -- dynamic libraries
copy from to
= getDirectoryContents from
>>= mapM_ copy' . filter (not . uselessFile)
where
copy' f = do
let (from', to') = (from </> f, to </> f)
isDir <- doesDirectoryExist from'
if isDir
then createDirectory to' >> copy from' to'
else copyFile from' to'
與目標目錄中運行它作爲參數後,您將有lib
和mingw
(約300本地副本總共Mb)。
您可以從lib
中刪除未使用的庫以節省更多空間。
您可以手動指定'package.conf.d'的路徑而不是調用'libdir'。即''runGhc(只是「路徑\到\ ghc \ lib」)' – 2011-03-30 13:18:31
謝謝,但我的問題是關於如何完成ghc在我的應用程序在Windows上的最小嵌入,然後提到的具體錯誤。 – mentics 2011-03-30 13:37:35
在這種情況下,我不明白實際存在什麼問題。看起來你只需要將'lib'和'mingw'複製到你的zip文件中,並提供'runGhc'與這個'lib'的相對路徑(並且不要忘記從'lib'中刪除未使用的包和庫, )。 – 2011-03-30 14:17:17