我试图从Real World Haskell编写一个例子(第26章):
有一个C我想要调用的函数FFI:
#include <stdint.h>
#include <sys/types.h>
/* only accepts uint32_t aligned arrays of uint32_t */
void hashword2(const uint32_t *key, /* array of uint32_t */
size_t length, /* number of uint32_t values */
uint32_t *pc, /* in: seed1, out: hash1 */
uint32_t *pb); /* in: seed2, out: hash2 */
Run Code Online (Sandbox Code Playgroud)
这是尝试导入它的haskell代码:
{-# LANGUAGE BangPatterns, ForeignFunctionInterface #-}
import Data.Word (Word32, Word64)
import Foreign.C.Types (CSize)
import Foreign.Marshal.Utils (with)
import Foreign.Ptr (Ptr, castPtr, plusPtr)
import Foreign.Storable (Storable, peek, sizeOf) …Run Code Online (Sandbox Code Playgroud) 我正在关注Stephen Diehl在Linux Mint盒子上的优秀LLVM Haskell教程(Linux Mint 17 Qiana,GHC 7.8.4,llvm 3.4).
我克隆了项目的github repo,我能够通过使用包含来构建每个章节的示例Makefile.
在第4章中,本教程为我们提供了一个JIT编译器:
import qualified LLVM.General.ExecutionEngine as EE
jit :: Context -> (EE.MCJIT -> IO a) -> IO a
jit c = EE.withMCJIT c optlevel model ptrelim fastins
where
optlevel = Just 2 -- optimization level
model = Nothing -- code model ( Default )
ptrelim = Nothing -- frame pointer elimination
fastins = Nothing -- fast instruction selection
runJIT :: AST.Module -> IO (Either …Run Code Online (Sandbox Code Playgroud) 我正在使用ghc 7.6.3.我从这里安装了wxHaskell:https://github.com/wxHaskell/wxHaskell
它工作,示例程序编译和运行成功.
现在唯一的问题是我想在mac OS X上分发一个wxHaskell应用程序.我尝试使用macosx-app和cabal-macosx(https://github.com/michaelt/cabal-macosx)制作一个"app"文件.它在我的机器上运行正常,但无法在另一台计算机上运行.我收到以下错误:
Dyld Error Message: Library not loaded: /Users/user/.cabal/lib/wxc-0.90.1.0/ghc-7.6.3/libwxc.dylib.
Run Code Online (Sandbox Code Playgroud)
我使用的是OS X 10.8.4(Mountain Lion),但我也有兴趣在Windows上编译应用程序并重新分发它们.
什么是重新分发wxHaskell应用程序的最佳方法?
Setup.hs
-- Example Setup.hs for the wxHello app.
import Distribution.MacOSX
import Distribution.Simple
main :: IO ()
main = defaultMainWithHooks $ simpleUserHooks {
postBuild = appBundleBuildHook guiApps -- no-op if not MacOS X
}
guiApps :: [MacApp]
guiApps = [MacApp "WxHello"
(Just "resources/WxHello.icns")
Nothing -- Build a default Info.plist for the icon.
[] -- No other resources.
[] …Run Code Online (Sandbox Code Playgroud)