代码之家  ›  专栏  ›  技术社区  ›  Jogger

为什么堆栈不将我的ghc选项传递给编译器?

  •  4
  • Jogger  · 技术社区  · 8 年前

    -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
    

    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选项“-ddump hi-ddump to file”

    为什么我看不到我的GHC选项 -墙壁-O2 ? (恐怕我犯了一些愚蠢的小错误……)

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

    1 回复  |  直到 8 年前
        1
  •  4
  •   gallais    8 年前

    选项 -ddump-hi -ddump-to-file 正在通过 按堆栈到阴谋集团 . 然后,阴谋集团将其添加到 .cabal 在将其传递给GHC之前归档。

    如果使用以下选项运行堆栈:

    stack -v --cabal-verbose
    

    正如@epsilonhalbe所指出的,当GHC发现这些问题时,它并没有抱怨更多的小问题 main 缺少,因此如果您添加:

    main = undefined
    

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