2010-07-12 75 views
3

我需要爲這個模塊哈斯克爾編譯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 

我編譯創建DLL:

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

我也有dllMain.o這就像http://haskell.org/ghc/docs/6.12.1/html/users_guide/win32-dlls.html和MyDef.def創建。從那以後,我下一步:

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 [email protected] 
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 

據我瞭解zhcon失敗,因爲必須有一個根模塊。但爲什麼我可以使用Foreign。*?爲什麼我不能使用HighAPI模塊?我應該把整個程序寫在一個文件中嗎? 謝謝。

回答

2

GHC 6.12支持創建一個包含Haskell庫及其所有依賴項(包括RTS)的單個DLL。它不能創建相互調用的Haskell代碼的單獨DLL,儘管該功能已經實現並可能在即將到來的GHC 6.14.1中提供。

要回答你的問題,你需要鏈接HighAPI模塊,當你創建的DLL與ghc -shared。有關創建Haskell DLL的更多信息,請參閱blog post by Neil Mitchell(請閱讀此信息,因爲GHC用戶指南中的信息對於幾件事情是錯誤的,特別是如何使用DllMain)。

+0

謝謝。我讀過這個博客。 我沒有看到那裏的例子如何創建鏈接到其他模塊的DLL。 – Anton 2010-07-15 05:52:09

+0

Anton:您需要將庫中的所有模塊鏈接在一起。例如'ghc -shared -o MarketNews.dll HighAPI.o MarketNews.o MarketNews_stub.o dllMain.o MyDef.def'。 – 2010-07-15 11:27:48

+0

它不起作用,我試了一次又一次。我得到這樣的錯誤: HighAPI.o:假:(文字+ 0x14f):未定義的引用'__stginit_datetimezm0zi2_D ataziDateTime_」 collect2:LD返回1退出狀態 – Anton 2010-07-15 16:20:15