2012-03-10 66 views
2

我創建了一個非常簡單的程序:GHC編譯錯誤

module CompileTest(main) where 

main = putStrLn "Hello, World!" 

當我嘗試編譯使用ghc CompileTest.hs我得到它:

/usr/lib/ghc-6.12.1/libHSrtsmain.a(Main.o): In function `main': 
(.text+0x10): undefined reference to `ZCMain_main_closure' 
/usr/lib/ghc-6.12.1/libHSrtsmain.a(Main.o): In function `main': 
(.text+0x18): undefined reference to `__stginit_ZCMain' 

有誰知道這是什麼嗎?我沒有做任何複雜的事情。它在GHCi中工作正常。

+2

作爲托馬斯'回答的補充,用'-main-is'標誌,'main'函數不需要叫'main',你可以使用'ghc --make -main-is Foo.bar Foo .hs'用模塊'Foo'中的函數'bar'作爲入口點進行編譯。 – 2012-03-10 16:35:53

回答

5

main函數必須位於Main模塊中。那還是使用GHC標誌-main-is。另外,您需要使用--make的編譯標誌與GHC < 7。

+0

GHC 7不再需要'--make'了嗎?我不知道。 – 2012-03-11 04:47:44