Haskell compile dll
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
g开发者_运维知识库etNextNewsInfoM = 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.
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
).
精彩评论