Cabal build with c2hs not finding .chs module

386 views Asked by At

I am trying out c2hs, and wanted to compile a small example of a shared library with Cabal to get started.

I have the following relevant section of the cabal file 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

Then the source. src/Dummy.hs:

import Test

main :: IO ()
main = return

In the file src/Test.chs

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

module Android where

And then when I try to compile (cabal configure && cabal build -v) I get the following error message:

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.

Please, can you tell me what the cause of the error is? What am I missing?

1

There are 1 answers

2
Michael Snoyman On BEST ANSWER

You need to add Test to the other-modules field.