【问题标题】:Cabal library cannot import exposed modulesCabal 库无法导入暴露的模块
【发布时间】:2018-03-08 07:35:19
【问题描述】:

我的 foo.cabal 文件如下所示:

library
  exposed-modules:
      Foo.Bar,
      Foo.Something
  hs-source-dirs:      lib
  default-language:    Haskell2010

executable foobar
  main-is:             Main.hs
  other-modules:
      Utils,  -- Local module in ./src
      Foo.Bar

  hs-source-dirs:      src
  default-language:    Haskell2010

根据这里的示例代码: https://www.haskell.org/cabal/users-guide/developing-packages.html#example-a-package-containing-a-library-and-executable-programs

我收到以下错误:

$ cabal build
Resolving dependencies...
Configuring foobar-0.1.0.0...
Preprocessing executable 'foobar' for foobar-0.1.0.0..
cabal: can't find source for Foo/Bar in src, dist/build/foobar/autogen,
dist/build/global-autogen

【问题讨论】:

    标签: haskell cabal


    【解决方案1】:

    build-depends: foo 行添加到您的可执行节中,以指示可执行文件取决于您定义的库。

    【讨论】:

      【解决方案2】:

      您必须将库添加到可执行文件的依赖项中。这是你的 cabal 文件的 hpack 版本,我永远记不住 cabal 语法:

      name: foo
      version: 0.1.0
      dependencies:
        - base
      
      source-dirs: lib
      
      # no need for exponsed-modules, hpack does that for you
      
      executable:
        main: Main.hs
        source-dirs: src
        dependencies:
          - base
          - foo
      

      或者只使用stack new,你就会得到一个工作项目。

      【讨论】:

      • 没有办法绕过堆栈吧?虽然对于 cabal 来说似乎是一件如此简单的事情,但我想知道在我进行转换之前是否可以从中获得更多里程
      • 抱歉,我实际上已切换到 hpack,但仍然无法获得所需的行为。我需要公开一些库并将公开的模块作为依赖项添加到可执行文件中。此解决方案不声明库部分。
      猜你喜欢
      • 1970-01-01
      • 2021-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多