haskell - 如何诊断 "Perhaps you need to add xxx to the build-depends in your .cabal file",当它已经在 cabal 文件中时?

标签 haskell haskell-stack

我认为唯一有趣的部分是我的导入和我的阴谋文件。以下是我将如何使用有问题的导入 ( Database.CQL.IO.Log ) 的导入和演示。

module FDS.Database.Cassandra where

import           Prelude                         hiding(init)
import           Database.CQL.IO                 as Client hiding(Logger)
import           Database.CQL.IO.Log             as CQLLog
import qualified Database.CQL.Protocol           as CQL
import           Numeric.Natural
import           System.Logger                   (Logger)

cqlLogger :: Logger -> CQLLog.Logger
cqlLogger logger = undefined

但是,我收到错误:
src/FDS/Database/Cassandra.hs:7:1: error:                                                                                              
    Could not load module `Database.CQL.IO.Log'                                                                                                                                    
    It is a member of the hidden package `cql-io-1.1.0'.                                                                                                                           
    Perhaps you need to add `cql-io' to the build-depends in your .cabal file.                                                                                                     
    Use -v to see a list of the files searched for.                                                                                                                                
  |                                                                                                                                                                                
7 | import           Database.CQL.IO.Log             as CQLLog                                                                                                                     
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^                                                                                                                     

但是正如我们从 cabal 文件中看到的那样,它在那里:
library
  ghc-options:    -Wall -Wtabs -Wincomplete-record-updates
  default-extensions:
      OverloadedStrings

  exposed-modules:
    FDS
    , FDS.Config.Core
    , FDS.Config.Dhall
    , FDS.Data.Util
    , FDS.Database.Cassandra

  other-modules:
    FDS.Data.Hobo.Defs

  build-depends:
    prelude
    , base-noprelude    ^>=4.12
    , bytestring        ^>=0.10.8.2
    , conduit           ^>=1.3.1
    , containers        ^>=0.6
    , cql               ^>=4.0.1
    , cql-io            ^>=1.1.0

需要注意的一件事,我的 extra-deps 中确实有 cql-io在 stack.yaml ,因为最新版本尚未在 LTS 中。

来自评论的问答

您的 cabal 文件中是否还有其他组件(例如可执行文件、基准测试、测试套件)?

一个 是的

他们是否也使用 FDS.Database.Cassandra(但可能不依赖于 cql-io)?

一个 还没有,但计划稍后。所以我还没有触及其他组件。

你的构建工具选择的cql-io版本是否仍然导出Database.CQL.IO.Log?

一个 seems to do so .

当您看到该错误时,您正在运行的确切命令是什么?

一个 stack --nix build唯一有趣的一点是--nix正在做 (AFAIK) 正在拉入所需的系统包,例如 OpenSSL。

最佳答案

上面的评论对于问题的一般情况(如所提出的)非常有见地;答案是,最近由 cabal 支持的子库可能没有 visibility: true宣布。

但在我的具体情况下,答案是查看有问题的库的再导出。我可以解决这个问题,因为 cql-io 作者重新导出了 Logger (..)LogLevel(..)从主图书馆。

这样我就可以编写代码了。

当我尝试使用 TinyLog 时,针对我的情况的一个更好的答案是 is a library已经... here is the code来自那个演示如何解决问题的库(并为我完全解决了问题,因为我现在不必编写任何代码)。

以下是相关摘录:

module Database.CQL.IO.Tinylog (mkLogger) where

import Data.ByteString.Builder
import Data.ByteString.Lazy (ByteString)
import Database.CQL.IO (Logger (..), LogLevel (..))
import Database.CQL.IO.Hexdump

import qualified Data.ByteString.Lazy as L
import qualified System.Logger        as Tiny

-- | Create a cql-io 'Logger' that delegates log messages to
-- the given tinylog 'Tiny.Logger'. Requests and responses are
-- logged on 'Tiny.Trace' level.
mkLogger :: Tiny.Logger -> Logger
mkLogger l = Logger
    { logMessage  = tinylogMessage  l
    , logRequest  = tinylogRequest  l
    , logResponse = tinylogResponse l
    }

这是我在上面的示例中调整我的导入以确认并让 GHC 满意的方法(尽管我现在将取消它以支持使用 cql-io-tinylog ):
import           Prelude                         hiding(init, log)
import           Database.CQL.IO                 hiding(Logger)
import qualified Database.CQL.IO                 as CQLIO
import qualified Database.CQL.Protocol           as CQL
import           Numeric.Natural
import           System.Logger                   hiding(defSettings)

关于haskell - 如何诊断 "Perhaps you need to add xxx to the build-depends in your .cabal file",当它已经在 cabal 文件中时?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54699019/

相关文章:

haskell - 警告 : newtype `CInt' is used in an FFI declaration,

parsing - 在解析器组合器中组合词法分析器和解析器

docker - 使用 docker : true 时获取堆栈以获取 GHCJS 内置 docker 图像

haskell - 静态链接二进制文件中缺少调试符号

haskell - 将 +RTS 选项传递给使用 stack exec 运行的程序

haskell - VS Code Haskell 扩展 - 无法确定项目使用的 GHC 版本

haskell - 为什么这个 Functor 实例不正确?

haskell - 应用仿函数分析

Haskell:使用规则列表过滤列表

unit-testing - 使用 "stack test"时,我的 hspec 测试输出未着色