Skip to content
Create a gist now

Instantly share code, notes, and snippets.

ghci doesn't work with FFI export declarations?
#include <stdio.h>
void callMeFromC(void);
void callMeFromHaskell(void)
{-# 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"
return ()
GHC_OPT := -Wall -O2 -fno-warn-unused-do-bind
all: ffiso
test: ffiso
ffiso: FFISo.hs c.c
ghc --make $(GHC_OPT) $^ -o $@
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

Unfortunately only with -fobject-code which also disables debugging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.