[Haskell-cafe] Multiple instancing of functions with FFI
Lewis-Sandy, Darrell
darrelll at amgen.com
Mon Jul 9 20:48:47 EDT 2007
I am having trouble exporting multiple instances of a polymorphic function
similar to the example in the "Haskell 98 Foreign Function Interface 1.0
addendum" (page 6). My specific code is below:
-----------------------begin test.hs---------------------------------
>module Test() where
>import Foreign
>import Foreign.C
>foreign export stdcall "addByte" (+):: Int8->Int8->Int8
>foreign export stdcall "addInt" (+):: Int16->Int16->Int16
>foreign export stdcall "addLong" (+):: Int32->Int32->Int32
-----------------------end test.hs---------------------------------
This somewhat contrived example should export three foreign implementations
of integer addition (one for each of 8, 16 and 32 byte integers). I am
compiling to a Win 32 DLL with GHC 6.61 using the following set of commands:
--------------------------------------------------------
ghc -c adder.hs -fglasgow-exts -ffi
ghc -c dllMain.c
ghc -static --mk-dll -optdll--def=test.def -o test.dll test.o test_stub.o
dllMain.o
--------------------------------------------------------
where dllMain.c declares my entry point for the DLL, and is as follows
--------------------begin dllMain.c------------------------------------
#include <windows.h>
#include <Rts.h>
extern void __stginit_Adder(void);
static char* args[] = { "ghcDll", NULL };
BOOL STDCALL DllMain ( HANDLE hModule, DWORD reason, void* reserved )
{
if (reason == DLL_PROCESS_ATTACH) {
startupHaskell(1, args, __stginit_Adder);
return TRUE;
}
if (reason == DLL_PROCESS_DETACH) {
shutdownHaskell();
return TRUE;
}
return TRUE;
}
----------------------------end dllMain.c----------------------------
and I have declared the exported function names explicitly in test.def:
---------------------------begin test.def-----------------------------
EXPORTS
addByte
addInt
addLong
----------------------------end test.def----------------------------
Upon compilation, I receive a long list of errors including things like
"error:redefinition of 'stginit_export_Test_zdfzp' was here", etc. Any help
would be appreciated.
Darrell
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20070709/1a2a1585/attachment-0001.htm
More information about the Haskell-Cafe
mailing list