2015-06-24 85 views
1

我正在嘗試c2hs,並且想編譯一個Cabal的共享庫的小例子來開始。Cabal搭配c2hs找不到.chs模塊

我有小集團文件test.cabal以下相關章節:

executable libtest.so 
    hs-source-dirs:  src 
    main-is:    Dummy.hs 
    other-extensions: ForeignFunctionInterface 
    build-depends:  base 
    default-language: Haskell2010 
    ghc-options:   -no-hs-main -threaded 
    build-tools:   c2hs 

然後來源。 src/Dummy.hs

import Test 

main :: IO() 
main = return 

在文件src/Test.chs

{-# LANGUAGE ForeignFunctionInterface #-} 
import Foreign 
import Foreign.C 

module Android where 

,然後當我嘗試編譯(cabal configure && cabal build -v)我收到以下錯誤信息:

Component build order: executable 'libtest.so' 
creating dist/build 
creating dist/build/autogen 
Building test-0.1.0.0... 
Preprocessing executable 'libtest.so' for test-0.1.0.0... 
Building executable libtest.so... 
creating dist/build/libtest.so 
creating dist/build/libtest.so/libtest.so-tmp 
/opt/ghc/bin/ghc --make -no-link -fbuilding-cabal-package -O -j8 -static 
-outputdir dist/build/libtest.so/libtest.so-tmp -odir dist/build 
/libtest.so/libtest.so-tmp -hidir dist/build/libtest.so/libtest.so-tmp-stubdir 
dist/build/libtest.so/libtest.so-tmp -i -idist/build/libtest.so/libtest.so-tmp 
-isrc -idist/build/autogen -Idist/build/autogen 
-Idist/build/libtest.so/libtest.so-tmp 
-optP-include -optPdist/build/autogen/cabal_macros.h -hide-all-packages 
-package-db dist/package.conf.inplace -package-id 
base-4.7.0.1-1a55ebc8256b39ccbff004d48b3eb834 -XHaskell2010 
src/Dummy.hs -no-hs-main -threaded 

src/Dummy.hs:1:8: 
    Could not find module ‘Test’ 
Use -v to see a list of the files searched for. 

,能不能請你告訴我錯誤的原因是什麼?我錯過了什麼?

回答

2

您需要將Test添加到其他模塊字段。

+0

但是,不是出口模塊,就好像它是一個庫? – rhaps0dy

+1

不,這是爲了告訴Cabal關於它不一定能夠自己弄清楚的模塊(這可能出於許多有效的原因...不值得潛入這裏)。在這種情況下,Cabal需要知道它需要爲GHC生成.hs文件。 –