首页 > 解决方案 > 当似乎正确指定时,如何修复 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                                                                                                            
  | ^^^^^^^^^^^^^^^^^^^^^^     

当然,我也对这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      .      

标签: haskellcabal

解决方案


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

mkdir program ; mv src/Main.hs program/

在 cabal 中用于可执行文件

hs-source-dirs: program

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


推荐阅读