为什么堆栈不将我的ghc-options传递给编译器? [英] Why does stack not pass my ghc-options to the compiler?
问题描述
在阴谋文件中,我指定了GHC选项 -Wall
和 -O2
:
In the cabal file I specify the GHC options -Wall
and -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:
When I compile the program 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
关于丢失的主要动作的错误不是问题。
看第二行最后一行的文本:
The error about the missing main action is not the problem. Look at the text at the end of the second last line:
build exe:Test --ghc-options- ddump-hi -ddump-to-file
build exe:Test --ghc-options " -ddump-hi -ddump-to-file"
为什么我看不到我的GHC选项 -Wall -O2 ? (我担心,我犯了一些愚蠢的小错误……)
Why do I not see my GHC options -Wall -O2? (I fear, I did some stupid little mistake ...)
PS:
堆栈版本为:版本1.5.1,Git修订版600c1f01435a10d127938709556c1682ecfd694e (4861次提交)x86_64 hpack-0.17.1
LTS:8.17
PS:
stack version is: Version 1.5.1, Git revision 600c1f01435a10d127938709556c1682ecfd694e (4861 commits) x86_64 hpack-0.17.1
LTS: 8.17
推荐答案
选项 -ddump-hi -ddump-to-file
正在由堆栈传递给Cabal 。 Cabal然后将它们添加到 .cabal
文件中指定的选项中,然后再将其传递到GHC。
The options -ddump-hi -ddump-to-file
are being passed by Stack to Cabal. Cabal then adds them to the options specified in the .cabal
file before passing them along to GHC.
使用以下命令运行堆栈:
If you run Stack with:
stack -v --cabal-verbose
并搜索输出,您会看到您的选项实际上是传递给了GHC。
and search through the output, you'll see that your options are in fact being passed to GHC.
正如@epsilonhalbe指出的那样,GHC发现缺少主要
时没有抱怨更小的问题,因此,如果您添加:
As @epsilonhalbe noted, GHC isn't complaining about the more minor issues when it discovers that main
is missing, so if you add:
main = undefined
在程序底部,您将收到期望的警告。
to the bottom of your program, you'll get the warnings you're expecting.
这篇关于为什么堆栈不将我的ghc-options传递给编译器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!