haskell - 无法定义多个可执行文件

标签 haskell haskell-stack

我在 app 文件夹中有两个文件

app/
|-- Main.hs
|-- SomeFunc2.hs

SomeFunc2.hs 只是打印不同的字符串

module SomeFunc2 where

import Lib

main :: IO ()
main = putStrLn "someFunc2"

当我像这样在 package.yaml 中定义多个可执行文件时

executables:
  multiexes-exe:
    main:                Main.hs
    source-dirs:         app
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - multiexes

  somefunc2-exe:
    main:                SomeFunc2.hs
    source-dirs:         app
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - multiexes

我收到错误:

▸ stack build
Building all executables for `multiexes' once. After a successful build of all of them, only specified executables will be rebuilt.
multiexes-0.1.0.0: configure (lib + exe)
Configuring multiexes-0.1.0.0...
multiexes-0.1.0.0: build (lib + exe)
Preprocessing library for multiexes-0.1.0.0..
Building library for multiexes-0.1.0.0..
[2 of 2] Compiling Lib              ( src/Lib.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.1.0/build/Lib.o )
Preprocessing executable 'multiexes-exe' for multiexes-0.1.0.0..
Building executable 'multiexes-exe' for multiexes-0.1.0.0..
[1 of 3] Compiling Main             ( app/Main.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.1.0/build/multiexes-exe/multiexes-exe-tmp/Main.o ) [Lib changed]
[3 of 3] Compiling SomeFunc2        ( app/SomeFunc2.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.1.0/build/multiexes-exe/multiexes-exe-tmp/SomeFunc2.o )
Linking .stack-work/dist/x86_64-osx/Cabal-2.0.1.0/build/multiexes-exe/multiexes-exe ...
Preprocessing executable 'somefunc2-exe' for multiexes-0.1.0.0..
Building executable 'somefunc2-exe' for multiexes-0.1.0.0..
Warning: Enabling workaround for Main module 'Main' listed in 'other-modules'
illegaly!
[1 of 2] Compiling Paths_multiexes  ( .stack-work/dist/x86_64-osx/Cabal-2.0.1.0/build/somefunc2-exe/autogen/Paths_multiexes.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.1.0/build/somefunc2-exe/somefunc2-exe-tmp/Paths_multiexes.o )
[2 of 2] Compiling SomeFunc2        ( app/SomeFunc2.hs, .stack-work/dist/x86_64-osx/Cabal-2.0.1.0/build/somefunc2-exe/somefunc2-exe-tmp/SomeFunc2.o )

<no location info>: error:
    output was redirected with -o, but no output will be generated
because there is no Main module.


--  While building custom Setup.hs for package multiexes-0.1.0.0 using:
      /Users/leo/.stack/setup-exe-cache/x86_64-osx/Cabal-simple_mPHDZzAJ_2.0.1.0_ghc-8.2.2 --builddir=.stack-work/dist/x86_64-osx/Cabal-2.0.1.0 build lib:multiexes exe:multiexes-exe exe:somefunc2-exe --ghc-options " -ddump-hi -ddump-to-file -fdiagnostics-color=always"
    Process exited with code: ExitFailure 1

如何解决?谢谢!

最佳答案

找到了一个解决方案,如果我为每个可执行文件创建一个文件夹并在每个文件夹中都有一个 Main.hs ,那么它就可以工作。

app/
|-- Main.hs
somefunc2/
|-- Main.hs

在 package.yaml 中,将 source-dirs 更改为这些文件夹:

executables:
  multiexes-exe:
    main:                Main.hs
    source-dirs:         app
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - multiexes

  somefunc2-exe:
    main:                Main.hs
    source-dirs:         somefunc2
    ghc-options:
    - -threaded
    - -rtsopts
    - -with-rtsopts=-N
    dependencies:
    - multiexes

关于haskell - 无法定义多个可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50818254/

相关文章:

haskell - 类型声明有什么问题吗?

haskell - 确保两个 (G) ADT 在 (GHC) Haskell 中具有相同的底层表示

haskell - 堆栈不支持的版本

docker - 为什么我的Haskell程序不能在带有Alpine或Scratch的Docker中运行?

Haskell,局部定义和变量,混淆 :/

haskell - 使用 cabal 进行个人项目的常见工作流程是什么?

c - Haskell - 相当于 for 循环?

haskell - stack --nix build 提示 ghc 版本不匹配

haskell - 如何检查堆栈安装了哪个版本的软件包?

haskell - 离线安装和运行 haskell 包