tags:

views:

102

answers:

1

Hello . I need to create dll for this module

module MarketNews where
import Foreign
import Foreign.C.Types
import Foreign.C.String

import HighAPI(getNextNewsInfo)

getNextNewsInfoM :: IO CString
getNextNewsInfoM = getNextNewsInfo >>= \x -> newCString x

foreign export stdcall getNextNewsInfoM :: IO CString

I compiled :

 C:\Users\test_8\Documents\Project\MarketNews\src>ghc --make MarketNews.hs  -fglasgow
-exts

Also i have dllMain.o which created like http://haskell.org/ghc/docs/6.12.1/html/users_guide/win32-dlls.html and MyDef.def. After that i do next:

C:\Users\test_8\Documents\Project\MarketNews\src>ghc -shared -o MarketNews.dll M
arketNews.o MarketNews_stub.o dllMain.o MyDef.def
Creating library file: MarketNews.dll.a
Warning: resolving _getNextNewsInfoM by linking to _getNextNewsInfoM@0
Use --enable-stdcall-fixup to disable these warnings
Use --disable-stdcall-fixup to disable these fixups
MarketNews.o:fake:(.text+0x6b): undefined reference to `HighAPI_getNextNewsInfo_
closure'
MarketNews.o:fake:(.text+0x12d): undefined reference to `__stginit_HighAPI_'
MarketNews.o:fake:(.data+0x10): undefined reference to `HighAPI_getNextNewsInfo_
closure'
collect2: ld returned 1 exit status

As i understand it faild because there must be a single root module. But why do i can use Foreign.* ? Why does i can not use HighAPI module ? Should i write whole programm in one file ? Thanks.

+1  A: 

GHC 6.12 supports creating a single DLL containing a Haskell library and all of its dependencies, including the RTS. It can't create separate DLLs of Haskell code that call each other, although that feature is implemented and may be available in the forthcoming GHC 6.14.1.

To answer your question, you need to also link in the HighAPI module when you create the DLL with ghc -shared. More information about creating Haskell DLLs is available in a blog post by Neil Mitchell (read this, because the information in the GHC user guide is wrong about a few things, in particular how to use DllMain).

Simon Marlow
Thanks. I read this blog.I did not see there the example how to create DLL with link to other modules.
Anton
Anton: you need to link *all* the modules in your library together. e.g. `ghc -shared -o MarketNews.dll HighAPI.o MarketNews.o MarketNews_stub.o dllMain.o MyDef.def`.
Simon Marlow
It does not work , i am tried it later and again. I get errors like: HighAPI.o:fake:(.text+0x14f): undefined reference to `__stginit_datetimezm0zi2_DataziDateTime_'collect2: ld returned 1 exit status
Anton
I think it error comes from Data.DateTime module . How i can link to it ?
Anton
Success. I found out how to link package. : *ghc -shared -o MarketNews.dll HighAPI.o MarketNews.o MarketNews_stub.o dllMain.o MyDef.def -package datetime*
Anton