2011-03-18 127 views
11

我想在需要訪問GHC API的Windows上部署應用程序。使用來自維基第一個簡單的例子:在Windows上部署應用程序的GHC API的簡單方法

http://www.haskell.org/haskellwiki/GHC/As_a_library

導致以下錯誤(編譯一體機哈斯克爾平臺上和執行上的另一個乾淨的Windows安裝): 的test.exe:找不到包數據庫在C:\ haskell \ lib \ package.conf.d

我想部署我的應用程序作爲一個簡單的zip文件,並且不要求用戶安裝任何東西。有沒有一種直接的方法可以將所需的GHC文件包含在該zip文件中,以便它能夠正常工作?

+0

您可以手動指定'package.conf.d'的路徑而不是調用'libdir'。即''runGhc(只是「路徑\到\ ghc \ lib」)' – 2011-03-30 13:18:31

+0

謝謝,但我的問題是關於如何完成ghc在我的應用程序在Windows上的最小嵌入,然後提到的具體錯誤。 – mentics 2011-03-30 13:37:35

+0

在這種情況下,我不明白實際存在什麼問題。看起來你只需要將'lib'和'mingw'複製到你的zip文件中,並提供'runGhc'與這個'lib'的相對路徑(並且不要忘記從'lib'中刪除未使用的包和庫, )。 – 2011-03-30 14:17:17

回答

2

這一計劃將所需的文件複製到指定目錄(僅在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' 

與目標目錄中運行它作爲參數後,您將有libmingw(約300本地副本總共Mb)。

您可以從lib中刪除未使用的庫以節省更多空間。

相關問題