如何修复 Cabal 中的“找不到模块”错误,当它似乎正确指定时?

bba*_*ker 1 haskell cabal

我目前在这个项目中根本没有使用堆栈(只是 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                                                                                                            
  | ^^^^^^^^^^^^^^^^^^^^^^     
Run Code Online (Sandbox Code Playgroud)

当然,我也对这条Wmissing-home-modules消息有点困惑,因为我似乎已经在我的阴谋集团文件中添加了这些。

我的 .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
Run Code Online (Sandbox Code Playgroud)

我的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      .      
Run Code Online (Sandbox Code Playgroud)

Tho*_*son 5

对于丢失的模块,将您的程序可执行文件放入一个目录中,以便 yoru 库的模块层次结构不可见:

mkdir program ; mv src/Main.hs program/
Run Code Online (Sandbox Code Playgroud)

并在 cabal 中用于可执行文件

hs-source-dirs: program
Run Code Online (Sandbox Code Playgroud)

对于您缺少的 module Dhall,将dhall构建依赖项添加到executablecabal 文件中的节。