I have this project on a subject 'Languages and Compilers' Where we write parsers in Haskell. At the moment I'm working on this 2-Arrow
project where we use the 'alex' and 'happy' libraries to create a parser.hs and lexer.hs file from a lexer.x and parser.y file. While trying to build my framework (cabal build
in the project directory) I get the following error message:
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 #-}
| ^
If they were error messages originating from the code I wrote I would at least have a direction to look for solutions, but these errors come from the /dist-newstyle/
folder. Which, in my understanding, is a folder for intermediate files used in building the program. So I'm kind of at a dead end at the moment, since reinstalling 'happy' and 'alex', and updating cabal to latest version all did not change anything. Does anyone have any advice for resolving this error? Any help is greatly appreciated!!
(project framework from uni: https://www.cs.uu.nl/docs/vakken/b3tc/downloads-2018/2-Arrow.zip (depends on 'happy' and 'alex' packages). At first I thought the problem could lay in the framework, but I checked with the professor, he stated that others had no issues, so I don't think that's the problem)
CodePudding user response:
I wasn't able to duplicate the problem with a fresh GHCup installation on Windows 10, but the error message suggests there might be an issue with an installed version of the GNU C Compiler (GCC) which the Glasgow Haskell Compiler (GHC) invokes to apply the C pre-processor to certain Haskell source files, including the Lexer.hs
source file that's being generated by Alex from the Lexer.x
file, and the Parser.hs
source file that's being generated by Happy from the Parser.y
file.
Try creating a simple test.hs
program that invokes the C pre-processor:
{-# LANGUAGE CPP #-}
#define HELLO "Hello, world!"
main = putStrLn HELLO
and try compiling with ghc test.hs
. Assuming that fails with the same error as above, try ghc -v test.hs
, and you should find lines in the output starting with:
*** C pre-processor
"C:\...\gcc.exe" "-E" "-undef" ...blah blah blah...
An excerpt from my successful compilation follows. Maybe you can spot what's going wrong with your installation. Note that mine invokes the GHCup-installed version of GCC and directs the output to a temporary file area where it's then compiled by GHC. If the wrong GCC is invoked or the temporary file area isn't writable for some reason, that might lead to the problem you're seeing.
*** 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 )
CodePudding user response:
I went to my seminar and asked the TA for help. After some time he proposed that maybe the folder location was the problem. Lo and behold, after moving the folder from my OneDrive folder (which is also saved locally) to my C:\\
directory, the project finally compiled! I have no idea why this would be the case, so I have posted another question here Folder location makes Haskell project incompileable.