Created
May 18, 2012 10:47
-
-
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"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*.hi | |
*_stub.* | |
ffiso |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
void callMeFromC(void); | |
void callMeFromHaskell(void) | |
{ | |
printf("callMeFromHaskell\n"); | |
callMeFromC(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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 () |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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