9

when I type stack run I get no error message but when I type stack ghci I get this error about multiple files use the same name , how I can solve it ?

(base) wejden@wejdenaydi:~/wejden$ stack ghci
Using main module: 1. Package `wejden' component wejden:exe:wejden-exe with main-is file: /home/wejden/wejden/app/Main.hs
Building all executables for `wejden' once. After a successful build of all of them, only specified executables will be rebuilt.
wejden> configure (lib + exe)
Configuring wejden-0.1.0.0...
wejden> initial-build-steps (lib + exe)
The following GHC options are incompatible with GHCi and have not been passed to it: -threaded
Configuring GHCi with the following packages: wejden

* * * * * * * *

Warning: Multiple files use the same module name:
         * Paths_wejden found at the following paths
           * /home/wejden/wejden/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0/build/autogen/Paths_wejden.hs (wejden:lib)
           * /home/wejden/wejden/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0/build/wejden-exe/autogen/Paths_wejden.hs (wejden:exe:wejden-exe)
* * * * * * * *

GHCi, version 8.10.4: https://www.haskell.org/ghc/  :? for help
[1 of 3] Compiling Lib              ( /home/wejden/wejden/src/Lib.hs, interpreted )
[2 of 3] Compiling Main             ( /home/wejden/wejden/app/Main.hs, interpreted )
[3 of 3] Compiling Paths_wejden     ( /home/wejden/wejden/.stack-work/dist/x86_64-linux-tinfo6/Cabal-3.2.1.0/build/autogen/Paths_wejden.hs, interpreted )
Ok, three modules loaded.
Loaded GHCi configuration from /tmp/haskell-stack-ghci/f99925e2/ghci-script
*Main Lib Paths_wejden> 
Wejdene
  • 93
  • 4

2 Answers2

15

For those who, like me, need very specific instructions, here it goes:

executables:        
  mypkgname-exe:        
    main:                Main.hs        
    source-dirs:         app        
    ghc-options:        
    - -threaded        
    - -rtsopts        
    - -with-rtsopts=-N        
    dependencies:        
    - stocks        
    when:        
    - condition: false        
      other-modules: Paths_mypkgname

where mypkgname needs to be replaced with your package name. I'm posting this because on my first attempt I had put the when clause in the wrong place.

Milad
  • 836
  • 7
  • 13
  • 1
    Also, I'm not sure if this is obvious or not, but if your package name happens to have a dash in it like my-pkg-name then replace any dashes with underscores – Rich R May 04 '22 at 17:07
11

This is a known issue with hpack: https://github.com/commercialhaskell/stack/issues/5439

In short, add this in your package.yaml, to your executable(s) or your library:

when:
- condition: false
  other-modules: Paths_wejden  # your package name here
Li-yao Xia
  • 31,896
  • 2
  • 33
  • 56