簡體   English   中英

`gcc.exe' 在 /dist-newstyle/ 文件夾中的 `C 預處理器' 階段失敗錯誤消息

[英]`gcc.exe' failed in phase `C pre-processor' error message in /dist-newstyle/ folder

我有一個主題為“語言和編譯器”的項目,我們用 Haskell 編寫解析器。 目前我正在研究這個2-Arrow項目,我們使用“alex”和“happy”庫從 lexer.x 和 parser.y 文件創建 parser.hs 和 lexer.hs 文件。 在嘗試構建我的框架(項目目錄中的cabal build )時,我收到以下錯誤消息:

C:\\ ... \2-Arrow\dist-newstyle\build\x86_64-windows\ghc-9.2.4\assignment-arrow-0.1.0.0\x\arrow\build\arrow\arrow-tmp\Lexer.hs:1:1: error:
    `gcc.exe' failed in phase `C pre-processor'. (Exit code: 1)
  |
 1| {-# OPTIONS_GHC -fno-warn-unused-binds -fno-warn-missing-signatures #-}
  | ^

C:\\ ... \2-Arrow\dist-newstyle\build\x86_64-windows\ghc-9.2.4\assignment-arrow-0.1.0.0\x\arrow\build\arrow\arrow-tmp\Parser.hs:1:1: error:
    `gcc.exe' failed in phase `C pre-processor'. (Exit code: 1)
  |
1 | {-# OPTIONS_GHC -w #-}  
  | ^

如果它們是源自我編寫的代碼的錯誤消息,我至少會找到尋找解決方案的方向,但這些錯誤來自/dist-newstyle/文件夾。 據我了解,這是用於構建程序的中間文件的文件夾。 所以我現在有點陷入死胡同,因為重新安裝“happy”和“alex”,並將 cabal 更新到最新版本都沒有改變任何東西。 有人對解決此錯誤有任何建議嗎? 任何幫助是極大的贊賞!!

(來自uni的項目框架: https ://www.cs.uu.nl/docs/vakken/b3tc/downloads-2018/2-Arrow.zip(取決於'happy'和'alex'包)。起初我以為問題可能出在框架上,但我問了教授,他說其他人沒有問題,所以我認為不是問題所在)

我無法通過在 Windows 10 上全新安裝 GHCup 來重現該問題,但錯誤消息表明 Glasgow Haskell 編譯器 (GHC) 調用的已安裝 GNU C 編譯器 (GCC) 版本可能存在問題將 C 預處理器應用於某些 Haskell 源文件,包括 Alex 從Lexer.x文件生成的Lexer.hs源文件,以及 Happy 從Parser.y文件生成的Parser.hs源文件。

嘗試創建一個調用 C 預處理器的簡單test.hs程序:

{-# LANGUAGE CPP #-}
#define HELLO "Hello, world!"
main = putStrLn HELLO

並嘗試使用ghc test.hs進行編譯。 假設失敗並出現與上述相同的錯誤,請嘗試ghc -v test.hs ,您應該在輸出中找到以以下內容開頭的行:

*** C pre-processor
"C:\...\gcc.exe" "-E" "-undef" ...blah blah blah...

下面是我成功編譯的摘錄。 也許您可以發現您的安裝出了什么問題。 請注意,我的調用 GHCup 安裝版本的 GCC 並將輸出定向到一個臨時文件區域,然后由 GHC 對其進行編譯。 如果調用了錯誤的 GCC 或者臨時文件區域由於某種原因不可寫,這可能會導致您看到的問題。

*** C pre-processor:
"C:\ghcup\ghc\9.2.5\lib\../mingw/bin/gcc.exe" "-E" "-undef" "-traditional" "-IC:\ghcup\ghc\9.2.5\lib\x86_64-windows-ghc-9.2.5\base-4.16.4.0\include" "-IC:\ghcup\ghc\9.2.5\lib\x86_64-windows-ghc-9.2.5\ghc-bignum-1.2\include" "-IC:\ghcup\ghc\9.2.5\lib\x86_64-windows-ghc-9.2.5\rts-1.0.2\include" "-include" "C:\ghcup\ghc\9.2.5\lib\x86_64-windows-ghc-9.2.5\rts-1.0.2\include\ghcversion.h" "-Dmingw32_BUILD_OS" "-Dx86_64_BUILD_ARCH" "-Dmingw32_HOST_OS" "-Dx86_64_HOST_ARCH" "-D__GLASGOW_HASKELL_TH__" "-D__SSE__" "-D__SSE2__" "-D__IO_MANAGER_WINIO__=1" "-D__IO_MANAGER_MIO__=1" "-includeC:\Users\buhr\AppData\Local\Temp\ghc7128_0\ghc_2.h" "-x" "assembler-with-cpp" "test.hs" "-o" "C:\Users\buhr\AppData\Local\Temp\ghc7128_0\ghc_1.hscpp"
!!! systool:cpp: finished in 31.25 milliseconds, allocated 0.311 megabytes
!!! Chasing dependencies: finished in 46.88 milliseconds, allocated 2.719 megabytes
Stable obj: {}
Stable BCO: {}
Ready for upsweep
  [NONREC
      ModSummary {
         ms_hs_date = 2022-12-18 20:54:57.2679991 UTC
         ms_mod = Main,
         ms_textual_imps = [(Nothing, Prelude)]
         ms_srcimps = []
      } []]
*** Deleting temp files:
Deleting: C:\Users\buhr\AppData\Local\Temp\ghc7128_0\ghc_2.h
compile: input file C:\Users\buhr\AppData\Local\Temp\ghc7128_0\ghc_1.hscpp
*** Checking old interface for Main (use -ddump-hi-diffs for more details):
[1 of 1] Compiling Main             ( test.hs, test.o )

我去了我的研討會並向助教尋求幫助。 一段時間后,他提出也許文件夾位置是問題所在。 你看,將文件夾從我的 OneDrive 文件夾(也保存在本地)移動到我的C:\\目錄后,項目終於編譯了,我不知道為什么會這樣,所以我在這里發布了另一個問題文件夾位置使 Haskell 項目無法編譯

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM