Skip to content

Instantly share code, notes, and snippets.

@lewurm
Created May 18, 2012 10:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lewurm/2724649 to your computer and use it in GitHub Desktop.
Save lewurm/2724649 to your computer and use it in GitHub Desktop.
ghci: "GHCi runtime linker: fatal error: I found a duplicate definition for symbol"
*.hi
*_stub.*
ffiso
http://stackoverflow.com/questions/10658104/ghci-runtime-linker-issue-when-using-ffi-declarations
http://stackoverflow.com/questions/10123040/ghci-doesnt-work-with-ffi-export-declarations-shared-libaries
#include <stdio.h>
void callMeFromC(void);
void callMeFromHaskell(void)
{
printf("callMeFromHaskell\n");
callMeFromC();
}
{-# LANGUAGE OverloadedStrings #-}
module Main where
import qualified Data.ByteString.Char8 as B
import FFIFun.Foo
main :: IO ()
main = do
B.putStrLn "main"
callMeFromC
callMeFromHaskell
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 $@
clean:
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