
Hi all, I'm trying to call the following C function. RFC_RC _stdcall RfcUTF8ToSAPUC(const RFC_BYTE *utf8, unsigned utf8Length, SAP_UC *sapuc, unsigned *sapucSize, unsigned *resultLength, RFC_ERROR_INFO *info) I wrote a foreign import for this function: foreign import ccall unsafe "sapnwrfc.h RfcUTF8ToSAPUC" f_RfcUTF8ToSAPUC :: RfcBytePtr -> CUInt -> SapUCPtr -> Ptr CUInt -> Ptr CUInt -> RfcErrorInfoPtr -> IO RfcRetCodeType But when compiling I keep getting this error: C:\Temp\Haskell\HSAP>ghc --make -LC:/Temp/nwrfcsdk/lib -lsapnwrfc SAP/Types.hs Test.hs [1 of 2] Compiling SAP.Types ( SAP/Types.hs, SAP/Types.o ) Linking Test.exe ... SAP/Types.o(.text+0x91c):fake: undefined reference to `RfcUTF8ToSAPUC@24' collect2: ld returned 1 exit status I ran nm.exe on the sapnwrfc.lib to see the exports and got this list: SAPNWRFC.dll: 00000000 I .idata$4 00000000 I .idata$5 00000000 I .idata$6 00000000 T .text 00000000 T _RfcUTF8ToSAPUC@24 U __IMPORT_DESCRIPTOR_SAPNWRFC 00000000 I __imp__RfcUTF8ToSAPUC@24 It looks like RfcUTF8ToSAPUC@24 exists. I tried prepending a _ but it doesn't change anything. GHC tries to link directly to the .dll file and not to the .lib file. Is this a problem? Should I convert the .lib to a .a and link the .a? Is there a way to list the exports directly from the dll file? Thanks, Olivier.

Hello Olivier, Thursday, May 15, 2008, 1:26:28 AM, you wrote:
RFC_RC _stdcall RfcUTF8ToSAPUC(const RFC_BYTE *utf8, unsigned utf8Length, SAP_UC *sapuc, unsigned *sapucSize, unsigned *resultLength, RFC_ERROR_INFO *info)
foreign import ccall unsafe "sapnwrfc.h RfcUTF8ToSAPUC" f_RfcUTF8ToSAPUC :: RfcBytePtr -> CUInt -> SapUCPtr -> Ptr
use stdcall instead of ccall in Haskell too. afair, depending on calling conventions, different prefixes/suffixes are used when translating C function name into assembler (dll) name -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

On Wed, May 14, 2008 at 5:46 PM, Bulat Ziganshin
use stdcall instead of ccall in Haskell too. afair, depending on calling conventions, different prefixes/suffixes are used when translating C function name into assembler (dll) name
Oops, sorry I copied the wrong line in my e-mail. I'm using stdcall in the foreign import. I first tried with ccall and then realized the header was defining the stdcall convention when built on windows. The link error occurs when I use stdcall. When I use ccall it links but gives segmentation faults when I run the program. Here is the last import I used. foreign import stdcall unsafe "sapnwrfc.h RfcUTF8ToSAPUC" f_RfcUTF8ToSAPUC :: RfcBytePtr -> CUInt -> SapUCPtr -> Ptr CUInt -> Ptr CUInt -> RfcErrorInfoPtr -> IO RfcRetCodeType Thanks, Olivier.

Hi all, I found a solution to my linking problem, but it's a bit scary and I'm wondering if there is a simpler way to do this: The solution comes from the following article: http://www.emmestech.com/moron_guides/moron1.html To get ghc to link my dll properly I had to do the following: 1. Create a .def file from the sapnwrfc.lib using pexports.exe: 'pexports sapnwrfc.lib > sapnwrfc.def' 2. Edit the sapnwrfc.def file to add @24 at the end of the function I must call. ... RfcSubmitTransaction RfcTraceTest RfcUTF8ToSAPUC@24 <-- here ... 3. Create a 'sapnwrfc.a' import library using dlltool: 'dlltool --input-def sapnwrfc.def --dllname sapnwrfc.dll --output-lib libsapnwrfc.a -k' Is there a simpler way to do this? Some way of tricking ghc to search for RfcUTF8ToSAPUC instead of RfcUTF8ToSAPUC@24. It looks like ghc/ld/gcc (whoever is responsible) adds a @24 (number depends of args) at the end of the function name when the function is called using stdcall convention. Thanks, Olivier.
participants (2)
-
Bulat Ziganshin
-
Olivier Boudry