1

我正在尝试 c2hs,并想用 Cabal 编译一个共享库的小例子来开始。

我有以下 cabal 文件的相关部分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.

拜托,你能告诉我错误的原因是什么吗?我错过了什么?

4

1 回答 1

2

您需要将 Test 添加到 other-modules 字段。

于 2015-06-25T03:26:10.020 回答