2010-11-10 57 views
2

我寫了下面的文件temp.hs:與在data.set哈斯克爾程序犯規編譯

import qualified Data.Set 
import System.Environment 

main :: IO() 
main = do 
     args <- getArgs 
     let fname = head args 
     print (fname) 

它加載在ghci中沒有錯誤:

$ ghci 
GHCi, version 6.12.3: http://www.haskell.org/ghc/ :? for help 
Loading package ghc-prim ... linking ... done. 
Loading package integer-gmp ... linking ... done. 
Loading package base ... linking ... done. 
Loading package ffi-1.0 ... linking ... done. 
Prelude> :load temp.hs 
[1 of 1] Compiling Main    (temp.hs, interpreted) 
Ok, modules loaded: Main. 
*Main> 

當我嘗試編譯它,我得到以下錯誤:

$ ghc temp.hs -o temp 
Undefined symbols: 
    "___stginit_containerszm0zi3zi0zi0_DataziSet_", referenced from: 
     ___stginit_Main_ in temp.o 
ld: symbol(s) not found 
collect2: ld returned 1 exit status 

如果我把導入Data.Set出來,它編譯好。

版本信息:

$ ghc --version 
The Glorious Glasgow Haskell Compilation System, version 6.12.3 

$ gcc --ver 
Using built-in specs. 
Target: i686-apple-darwin10 
Configured with: /var/tmp/gcc_40/gcc_40-5494~112/src/configure --disable-checking -enable-werror --prefix=/usr --mandir=/share/man --enable-languages=c,objc,c++,obj-c++ --program-transform-name=/^[cg][^.-]*$/s/$/-4.0/ --with-gxx-include-dir=/include/c++/4.0.0 --with-slibdir=/usr/lib --build=i686-apple-darwin10 --with-arch=apple --with-tune=generic --host=i686-apple-darwin10 --target=i686-apple-darwin10 
Thread model: posix 
gcc version 4.0.1 (Apple Inc. build 5494) 
+0

此行爲不是特定於Mac,所以刪除'osx'和'mac'標籤和/或更改標題可能是一個好主意,因爲該問題可能對其他平臺上的用戶有用。 – 2010-11-10 20:42:10

+0

@ Travis Brown:謝謝!我刪除了標籤並更改了標題。 – highBandWidth 2010-11-10 20:45:20

回答

5

可以單獨添加軟件包(如KennyTM建議),或者您可以使用--make,這在多種方式中更方便:

ghc --make temp.hs -o temp 

這將導致GHC以與GHCi完全相同的方式在其安裝的軟件包中查找任何必需的模塊。

4
ghc -package containers temp.hs -o temp 

您可以檢查哪些包裝可以用ghci的,當你真正使用這個庫需要:

GHCi, version 6.12.3: http://www.haskell.org/ghc/ :? for help 
    Loading package ghc-prim ... linking ... done. 
    Loading package integer-gmp ... linking ... done. 
    Loading package base ... linking ... done. 
    Loading package ffi-1.0 ... linking ... done. 
    Ok, modules loaded: Main. 
    Prelude Main> Data.Set.singleton 0 
> Loading package array-0.3.0.1 ... linking ... done. 
> Loading package containers-0.3.0.0 ... linking ... done. 
    fromList [0] 
    Prelude Main>