Search code examples
haskellghccabal

"requested module differs from name found in the interface file"


What I want is: cabal to build my modules; make to build this one script.

The script links to Objective-C (see https://github.com/mchakravarty/language-c-inline/tree/master/tests/objc/marshal-array). when I build the script, it fails on the import:

$ make
Main.hs:1:1:
    Bad interface file: dist/build/Commands/OSX/Events.hi
        Something is amiss; requested module  main:Commands.OSX.Events differs from name found in the interface file commands-0.0.0:Commands.OSX.Events

here are some file contents:

$ cat Makefile
PACKAGES   = -package template-haskell -package language-c-quote -package language-c-inline -package commands
FRAMEWORKS = -framework Carbon -framework Cocoa -framework Foundation
LDFLAGS    = $(PACKAGES) $(FRAMEWORKS) 
Main: Main.o
    cabal exec -- ghc  -o Main Main.o $(LDFLAGS)
Main.o:
    cabal build
    cabal exec -- ghc  -c Main.hs -idist/build/ -v
...

$ cat commands.cabal
 exposed-modules: Commands.OSX.Events
 hs-source-dirs: sources
...

$ ghc --show-iface dist/build/Commands/OSX/Events.hi
interface commands-0.0.0:Commands.OSX.Events 7083
...

$ cat sources/Commands/OSX/Events.hs
module Commands.OSX.Events where
...

$ cat Main.hs
import Commands.OSX.Events
...

the cabal build is successful, and executable compiles and runs successfully, if I just put everything in the same directory, and ignore cabal.

  1. can I tell GHC that some module is part of some package?

  2. can I make a cabal executable, with these external dependencies?

  3. any other solutions?


Solution

  • explicitly naming the modules package worked:

    ghc -package-name commands-0.0.0
    

    http://www.haskell.org/ghc/docs/7.2.1/html/users_guide/packages.html