I made a short Haskell-program that exposes functions for C or Python. Followed http://www.haskell.org/ghc/docs/7.0.3/html/users_guide/ffi-ghc.html#ffi-library to the letter and that worked okay for exporting Ints.
Want to export Strings and made the program:
module Adder where
import CString
adder :: Int -> Int -> IO CString
adder x y = newCString(show(x+y))
foreign export ccall adder :: Int -> Int -> IO CString
That compiles okay when I do : ghc adder.hs but it fails when linking to create a dll in Windows.
ghc -shared -o adder.dll adder.o adder_stub.o StartEnd.o
The error: adder.o:fake:(.text+0x11d): undefined reference to `__stginit_haskell98zm1zi1zi0zi1_CString_'
The StartEnd.o is compiled from the C-file that I copied from the haskell.org-site :
#include <Rts.h>
extern void __stginit_Adder(void);
void HsStart()
{
int argc = 1;
char* argv[] = {"ghcDll", NULL}; // argv must end with NULL
// Initialize Haskell runtime
char** args = argv;
hs_init(&argc, &args);
// Tell Haskell about all root modules
hs_add_root(__stginit_Adder);
}
void HsEnd()
{
hs_exit();
}
What must I do to be able to export Strings ??
f (g x)
orf $ g x
orf . g $ x
– alternative