$PATH./usr/local/clang-3.0/ — not in your $PATH, since you don’t want to override Xcode’s clang)Unpack it, Run configure:
./configurearm-apple-darwin10-clangarm-apple-darwin10-ldllc from Clang+LLVM 3.0 (as downloaded above, e.g. /usr/local/clang-3.0/bin/llc)/usr/local/clang-3.0/bin/opt)Install the compiler:
make installUnpack it, Run configure:
./configurei386-apple-darwin11-clangi386-apple-darwin11-ldllc from Clang+LLVM 3.0 (as downloaded above, e.g. /usr/local/clang-3.0/bin/llc)/usr/local/clang-3.0/bin/opt)Install the compiler:
make install{-# LANGUAGE ForeignFunctionInterface #-}
module Counter where
import Control.Concurrent
import Control.Monad
foreign export ccall startCounter :: Int -> IO ()
startCounter :: Int -> IO ()
startCounter = void . forkIO . void . loop
where loop i = do
putStrLn (replicate i 'o')
threadDelay (10^6)
loop (i + 1)
ghc-ios Counter
(Counter.a will be a fat binary that works with both devices and the simulator.)
Create or open an Xcode project (the Single View Application template is simple for testing)
Drag Counter.a and Counter_stub.h to the project’s sidebar. Make sure “Add to Targets:” has a check next to your app.
/usr/local/lib/arm-apple-darwin10-ghc-7.8.0.20140228/include/ to “Header Search Paths” (ensure this matches the date of the GHC-iOS binary you downloaded)In your app’s AppDelegate.m:
#import "Counter_stub.h"and at the top of application:didFinishLaunchingWithOptions:, add:
hs_init(NULL, NULL);
startCounter(3);Run your app! You should see a growing triangle of ’o’s.
To install a package for the device and simulator, use cabal-ios (included in ghc-ios-scripts) like:
cabal-ios install textYou should now be able to use the package in a file compiled with ghc-ios. The package will be statically linked into the .a library.