Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
ghci: "GHCi runtime linker: fatal error: I found a duplicate definition for symbol"
#include <stdio.h>
void callMeFromC(void);
void callMeFromHaskell(void)
{-# LANGUAGE OverloadedStrings #-}
module Main where
import qualified Data.ByteString.Char8 as B
import FFIFun.Foo
main :: IO ()
main = do
B.putStrLn "main"
return ()
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ForeignFunctionInterface #-}
module FFIFun.Foo 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"
SHELL := bash
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,_stub.*} ffiso FFIFun/*{.hi,.o,_stub.*}
ghci: ffiso
ghci -package bytestring FFIFun/Foo.o c.o FFISo.hs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment