2
我想編譯下面的代碼。GHC鏈接問題
import Data.List
import Data.Ord
import qualified Data.MemoCombinators as Memo
collatzLength :: Int -> Int
collatzLength = Memo.arrayRange (1, 1000000) collatzLength'
where
collatzLength' 1 = 1
collatzLength' n | odd n = 1 + collatzLength (3 * n + 1)
| even n = 1 + collatzLength (n `quot` 2)
main = print $ maximumBy (comparing fst) $ [(collatzLength n, n) | n <- [1..1000000]]
的Haskell編譯吐出:
euler14.o: In function `s1pw_info':
(.text+0x8dd): undefined reference to `__stginit_datazmmemocombinatorszm0zi4zi1_DataziMemoCombinators_'
euler14.o: In function `rfX_info':
(.text+0x35d): undefined reference to `datazmmemocombinatorszm0zi4zi1_DataziMemoCombinators_arrayRange_info'
euler14.o: In function `rfX_srt':
(.data+0x4c): undefined reference to `datazmmemocombinatorszm0zi4zi1_DataziMemoCombinators_arrayRange_closure'
collect2: ld returned 1 exit status
我試着用搜索引擎,但無濟於事。有沒有可以查找這些錯誤的地方?他們的意思是什麼?
這些標識符讓我的眼睛受傷。那裏有C++嗎? –
你的GHC命令行是什麼樣的?你嘗試過'ghc --make Foo.hs'嗎? – hammar
我剛輸入ghc -O2 euler.hs。顯然它需要是ghc-O2 --make euler14.hs –