I am trying to call Haskell functions from python.
I have the following make file:
GHC=ghc
GHC_RUNTIME_LINKER_FLAG=-lHSrts-ghc7.4.1
libffi-example.so: Example.o wrapper.o
$(GHC) -o $@ -shared -dynamic -fPIC $^ $(GHC_RUNTIME_LINKER_FLAG)
Example_stub.h Example.o: Example.hs
$(GHC) -c -dynamic -fPIC Example.hs
wrapper.o: wrapper.c Example_stub.h
$(GHC) -c -dynamic -fPIC wrapper.c
clean:
rm -f *.hi *.o *_stub.[ch]
clean-all:
rm -f *.hi *.o *_stub.[ch] *.so
# Runs the example Python program
example: libffi-example.so
python program.py
The only thing wrapper.c does it creating wrappers for hs_init by calling hs_init(0,0);. The wrapper is called example_init
I get a segmentation fault when running make example, in example_init (ie when calling hs_init(0,0)).
Can someone tell me why this is and/or how to fix it?
Thanks!
It ought to work:
It seems to be a bug in ghc-7.2.1 to ghc-7.4.1:
RFib.hs:
rfib.c:
Compile and run:
Changing two lines in
rfib.c:it works with all versions (>= 7.0 that I have installed).
So to fix it
&argcand&argvare the two most obvious ways.