gpt4 book ai didi

haskell - 为什么堆栈不将我的 ghc-options 传递给编译器?

转载 作者:行者123 更新时间:2023-12-02 12:18:11 25 4
gpt4 key购买 nike

在 cabal 文件中,我指定了 GHC 选项 -Wall-O2:

name:               Test
version: 0.1.0.0
build-type: Simple
cabal-version: >=1.8

executable Test
hs-source-dirs: src
main-is: Test.hs
build-depends: base >=4.8 && <4.10
ghc-options: -Wall -O2

当我编译程序Test.hs时:

data Color = Red | Green | Blue

foo :: Color -> Int
foo Red = 0
foo Green = 1
-- foo Blue is intentionally missing!!

我收到错误:

Preprocessing executable 'Test' for Test-0.1.0.0...
[1 of 1] Compiling Main ( src/Test.hs, .stack-work/dist/x86_64-linux-nopie/Cabal-1.24.2.0/build/Test/Test-tmp/Main.o )

/home/user/Projekte/HaskellTutorials/Test/src/Test.hs:1:1: error:
The IO action ‘main’ is not defined in module ‘Main’

-- While building package Test-0.1.0.0 using:
/home/user/.stack/setup-exe-cache/x86_64-linux-nopie/Cabal-simple_mPHDZzAJ_1.24.2.0_ghc-8.0.2 --build
dir=.stack-work/dist/x86_64-linux-nopie/Cabal-1.24.2.0 build exe:Test --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1

有关缺少主要操作的错误不是问题。查看倒数第二行末尾的文本:

build exe:Test --ghc-options " -ddump-hi -ddump-to-file"

为什么我看不到我的 GHC 选项-Wall -O2? (我担心,我犯了一些愚蠢的小错误......)

PS:
堆栈版本为:版本 1.5.1,Git 修订版 600c1f01435a10d127938709556c1682ecfd694e(4861 次提交)x86_64 hpack-0.17.1
LTS:8.17

最佳答案

选项-ddump-hi -ddump-to-file正在由Stack传递到Cabal。然后 Cabal 将它们添加到 .cabal 文件中指定的选项中,然后将它们传递给 GHC。

如果您运行 Stack:

stack -v --cabal-verbose

并搜索输出,您会发现您的选项实际上已传递给 GHC。

正如 @epsilonhalbe 所指出的,当 GHC 发现 main 丢失时,它并不会提示更小的问题,因此如果您添加:

main = undefined

在程序底部,您会收到预期的警告。

关于haskell - 为什么堆栈不将我的 ghc-options 传递给编译器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46873934/

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