如何修复 Cabal 中的 "could not find module" 错误,当它似乎正确指定时?

How to fix a "could not find module" error in Cabal, when it seems correctly specified?

我目前在这个项目上根本没有使用堆栈(只是 Cabal),当一切都在 Main.hs 中时一切进展顺利。我决定拆分代码,将我的 dhall dep 和相关代码从我的可执行 deps 移动到我的库 deps,现在当 运行 cabal new-build:

时似乎出现了这个奇怪的错误
Building executable 'FarmDataServer.exe' for FarmDataServer-0.1.0.0..                                                                                                                                      
<no location info>: warning: [-Wmissing-home-modules]                                                                                 
    These modules are needed for compilation but not listed in your .cabal file's other-modules: FDS                                  
                                                                                                 FDS.Config.Core                      
                                                                                                 FDS.Config.DhallConf                 
[2 of 4] Compiling FDS.Config.DhallConf ( src/FDS/Config/DhallConf.hs, /home/brandon/workspace/CIDA/FarmDataServer/dist-newstyle/buil
d/x86_64-linux/ghc-8.4.4/FarmDataServer-0.1.0.0/x/FarmDataServer.exe/build/FarmDataServer.exe/FarmDataServer.exe-tmp/FDS/Config/Dhall
Conf.o )                                                                                                                              

src/FDS/Config/DhallConf.hs:7:1: error:                                                                                               
    Could not find module `Dhall'                                                                                                     
    Use -v to see a list of the files searched for.                                                                                   
  |                                                                                                                                   
7 | import           Dhall                                                                                                            
  | ^^^^^^^^^^^^^^^^^^^^^^     

当然,我也对 Wmissing-home-modules 消息感到有些困惑,因为我似乎已经在我的 cabal 文件中添加了这些消息。

我的 .cabal 文件的相关位:

cabal-version:       2.4
name:                FarmDataServer
version:             0.1.0.0

library
  exposed-modules:
    FDS

  other-modules:
    FDS.Config.Core
    , FDS.Config.DhallConf

  build-depends:       base             ^>=4.11.1.0
                       , conduit        ^>=1.3.1
                       , csv-conduit    ^>=0.7.0.0
                       , dhall          ^>=1.20.0
                       , text           ^>=1.2.3.1

  hs-source-dirs:      src



executable FarmDataServer.exe
  main-is:             Main.hs

  build-depends:       base             ^>=4.11.1.0
                       , conduit        ^>=1.3.1
                       , csv-conduit    ^>=0.7.0.0
                       , scotty         ^>=0.11.3
                       , text           ^>=1.2.3.1
                       , FarmDataServer ^>=0.1.0.0

我的 src 文件夹:

$ pwd                                                                                                                                 
/home/brandon/workspace/CIDA/FarmDataServer/src
$ du -a                                                                                                                               
4       ./FDS/Config/DhallConf.hs                                                                                                     
4       ./FDS/Config/Core.hs                                                                                                          
12      ./FDS/Config                                                                                                                  
16      ./FDS                                                                                                                         
4       ./FDS.hs                                                                                                                      
4       ./Main.hs                                                                                                                     
28      .      

对于缺少的模块,将您的程序可执行文件放入一个目录中,这样 yoru 库的模块层次结构将不可见:

mkdir program ; mv src/Main.hs program/

并在 cabal 中用于可执行文件

hs-source-dirs: program

对于缺少的模块 Dhall,将 dhall 构建依赖项添加到 cabal 文件中的 executable 节。