Haskell编译DLL

时间:2010-07-12 12:41:18

标签: dll haskell

我需要为这个模块创建dll

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

我编译:

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

我也有像http://haskell.org/ghc/docs/6.12.1/html/users_guide/win32-dlls.html和MyDef.def这样创建的dllMain.o。之后我做下一个:

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

据我所知,因为必须有一个根模块。但为什么我可以使用Foreign。*?为什么我不能使用HighAPI模块?我应该把整个程序写在一个文件中吗? 感谢。

1 个答案:

答案 0 :(得分:2)

GHC 6.12支持创建包含Haskell库及其所有依赖项的单个DLL,包括RTS。它不能创建相互调用的Haskell代码的单独DLL,尽管该功能已实现,可能会在即将推出的GHC 6.14.1中提供。

要回答您的问题,您还需要在使用HighAPI创建DLL时在ghc -shared模块中进行链接。有关创建Haskell DLL的更多信息,请参阅blog post by Neil Mitchell(请阅读此内容,因为GHC用户指南中的信息对于某些内容是错误的,特别是如何使用DllMain)。