public
Created

ghci doesn't work with FFI export declarations?

  • Download Gist
.gitignore
1 2 3
*.hi
*_stub.*
ffiso
FFISo.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ForeignFunctionInterface #-}
module Main where
 
import qualified Data.ByteString.Char8 as B
 
foreign import ccall "callMeFromHaskell"
callMeFromHaskell :: IO ()
 
foreign export ccall callMeFromC :: IO ()
callMeFromC :: IO ()
callMeFromC = B.putStrLn "callMeFromC"
 
main :: IO ()
main = do
B.putStrLn "main"
callMeFromHaskell
return ()
Makefile
Makefile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
GHC_OPT := -Wall -O2 -fno-warn-unused-do-bind
 
all: ffiso
 
test: ffiso
./$<
 
ffiso: FFISo.hs c.c
ghc --make $(GHC_OPT) $^ -o $@
 
clean:
rm -rf *.hi *.o ffiso *_stub.*
 
ghci0: ffiso
echo main | ghci FFISo.hs
 
ghci1: ffiso
echo main | ghci FFISo.hs c.o
 
ghci2: ffiso
echo main | ghci FFISo.hs c.o FFISo.o
README
1
http://stackoverflow.com/questions/10123040/ghci-doesnt-work-with-ffi-export-declarations-shared-libaries
c.c
C
1 2 3 4 5 6 7 8 9
#include <stdio.h>
 
void callMeFromC(void);
 
void callMeFromHaskell(void)
{
printf("callMeFromHaskell\n");
callMeFromC();
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.