gpt4 book ai didi

haskell - 从单个项目生成多个可执行文件

转载 作者:行者123 更新时间:2023-12-03 11:55:53 24 4
gpt4 key购买 nike

具有以下项目结构:

src/FirstExecutable.hs
src/SecondExecutable.hs
my-amazing-project.cabal

和以下 cabal 设置:
name:               my-amazing-project
version: 0.1.0.0
build-type: Simple
cabal-version: >=1.8

executable first-executable
hs-source-dirs: src
main-is: FirstExecutable.hs
ghc-options: -O2 -threaded -with-rtsopts=-N
build-depends: base == 4.5.*

executable second-executable
hs-source-dirs: src
main-is: SecondExecutable.hs
ghc-options: -O2 -threaded -with-rtsopts=-N
build-depends: base == 4.5.*

运行 cabal install失败并显示以下输出:
Installing executable(s) in
/Users/mojojojo/Library/Haskell/ghc-7.4.2/lib/my-amazing-project-0.1.0.0/bin
cabal: dist/build/second-executable/second-executable: does not exist
Failed to install my-amazing-project-0.1.0.0
cabal: Error: some packages failed to install:
my-amazing-project-0.1.0.0 failed during the final install step. The exception
was:
ExitFailure 1

我在做什么错还是这是 cabal 的错误?

可执行模块的内容如下:
module FirstExecutable where

main = putStrLn "Running FirstExecutable"


module SecondExecutable where

main = putStrLn "Running SecondExecutable"

最佳答案

cabal 期望可执行文件的模块为 Main .您应该跳过模块行或使用 module Main where .

好的,这是可能的原因。当模块不是 Main 时,不会生成 haskell 程序的可执行文件当你实际编译程序时。 main Main 的功能运行可执行文件时使用模块。 ghc 可能的解决方法是 -main-is旗帜。所以你可以有类似的东西

name:               my-amazing-project
version: 0.1.0.0
build-type: Simple
cabal-version: >=1.8

executable first-executable
hs-source-dirs: src
main-is: FirstExecutable.hs
ghc-options: -O2 -threaded -with-rtsopts=-N -main-is FirstExecutable
build-depends: base == 4.5.*

executable second-executable
hs-source-dirs: src
main-is: SecondExecutable.hs
ghc-options: -O2 -threaded -with-rtsopts=-N -main-is SecondExecutable
build-depends: base == 4.5.*

关于haskell - 从单个项目生成多个可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14238729/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com