GHC/GCC 编译器问题 __STDC_VERSION__ w/ C99 来自 Stg.h,每个包都失败

GHC/GCC compiler issue __STDC_VERSION__ w/ C99 from Stg.h, fails for every package

每当我尝试在 OSX 10.12.6 和 GCC 4.8.0 上安装带有 cabal(2.0.0) 的软件包时,我都会遇到以下关于 Stg.h 文件的错误GHC 8.2.1,错误非常神秘。我无法在 OSX 上安装任何软件包。

预期行为:

cabal install $packagename 应该在 OSX 上安装 $packagename,因为 cabal 和 cabal-install 已正确安装。

观察到的行为:

cabal install $packagename 由于与名为 __STDC_VERSION__ 的变量相关的低级 GHC/GCC 问题而失败。我不是 C 程序员,我不希望我正确安装 GHC 和 cabal 无法安装软件包。 AFAICT 此问题与用户错误无关。

Matthew@Mattmac git:the_D*+ ~/Projects/kata/euler>cabal update && cabal 
install optparse-applicative
Downloading the latest package list from hackage.haskell.org
gcc: warning: couldn’t understand kern.osversion ‘16.7.0
gcc: warning: couldn’t understand kern.osversion ‘16.7.0
Warning: --root-cmd is no longer supported, see
https://github.com/haskell/cabal/issues/3353 (if you didn't type --root-cmd,
comment out root-cmd in your ~/.cabal/config file)
Resolving dependencies...
Downloading transformers-compat-0.5.1.4...
Configuring colour-2.3.4...
Configuring transformers-compat-0.5.1.4...
Building colour-2.3.4...
Building transformers-compat-0.5.1.4...
Failed to install transformers-compat-0.5.1.4
Build log ( /Users/Matthew/.cabal/logs/ghc-8.2.1/transformers-compat-0.5.1.4-HHfl4KyHCH71PMx2CRgdve.log ):
cabal: Entering directory '/var/folders/qw/k0t4r5fd5_b0phjvwtxx_n700000gq/T/cabal-tmp-91946/transformers-compat-0.5.1.4'
Configuring transformers-compat-0.5.1.4...
gcc: warning: couldn’t understand kern.osversion ‘16.7.0
Preprocessing library for transformers-compat-0.5.1.4..
Building library for transformers-compat-0.5.1.4..
[1 of 2] Compiling Control.Monad.Trans.Instances ( src/Control/Monad/Trans/Instances.hs, dist/build/Control/Monad/Trans/Instances.o )
[2 of 2] Compiling Paths_transformers_compat ( dist/build/autogen/Paths_transformers_compat.hs, dist/build/Paths_transformers_compat.o )
[1 of 2] Compiling Control.Monad.Trans.Instances ( src/Control/Monad/Trans/Instances.hs, dist/build/Control/Monad/Trans/Instances.p_o )
In file included from /Library/Frameworks/GHC.framework/Versions/8.2.1-x86_64/usr/lib/ghc-8.2.1/include/Rts.h:30:0: error:
    0,
                     from /var/folders/qw/k0t4r5fd5_b0phjvwtxx_n700000gq/T/ghc92089_0/ghc_7.c:2:

/Library/Frameworks/GHC.framework/Versions/8.2.1-x86_64/usr/lib/ghc-8.2.1/include/Stg.h:30:3: error:
     error: #error __STDC_VERSION__ does not advertise C99 or later
     # error __STDC_VERSION__ does not advertise C99 or later
       ^
   |
30 | # error __STDC_VERSION__ does not advertise C99 or later
   |   ^
`gcc' failed in phase `C Compiler'. (Exit code: 1)
cabal: Leaving directory '/var/folders/qw/k0t4r5fd5_b0phjvwtxx_n700000gq/T/cabal-tmp-91946/transformers-compat-0.5.1.4'
Failed to install colour-2.3.4
Build log ( /Users/Matthew/.cabal/logs/ghc-8.2.1/colour-2.3.4-9c0ktEQZfar3Wigr5kT6BU.log ):
cabal: Entering directory '/var/folders/qw/k0t4r5fd5_b0phjvwtxx_n700000gq/T/cabal-tmp-91945/colour-2.3.4'
Configuring colour-2.3.4...
Preprocessing library for colour-2.3.4..
Building library for colour-2.3.4..
[ 1 of 14] Compiling Data.Colour.CIE.Chromaticity ( 
Data/Colour/CIE/Chromaticity.hs, dist/build/Data/Colour/CIE/Chromaticity.o )
...
[ 1 of 14] Compiling Data.Colour.CIE.Chromaticity ( Data/Colour/CIE/Chromaticity.hs, dist/build/Data/Colour/CIE/Chromaticity.p_o )

In file included from /Library/Frameworks/GHC.framework/Versions/8.2.1-x86_64/usr/lib/ghc-8.2.1/include/Rts.h:30:0: error:
    0,
                     from /var/folders/qw/k0t4r5fd5_b0phjvwtxx_n700000gq/T/ghc92201_0/ghc_3.c:2:

/Library/Frameworks/GHC.framework/Versions/8.2.1-x86_64/usr/lib/ghc-8.2.1/include/Stg.h:30:3: error:
     error: #error __STDC_VERSION__ does not advertise C99 or later
     # error __STDC_VERSION__ does not advertise C99 or later
       ^
   |
30 | # error __STDC_VERSION__ does not advertise C99 or later
   |   ^
`gcc' failed in phase `C Compiler'. (Exit code: 1)
cabal: Leaving directory '/var/folders/qw/k0t4r5fd5_b0phjvwtxx_n700000gq/T/cabal-tmp-91945/colour-2.3.4'
cabal: Error: some packages failed to install:
ansi-terminal-0.7.1.1-3eOIKoB8mo97DkHMJ6AgBw depends on ansi-terminal-0.7.1.1
which failed to install.
ansi-wl-pprint-0.6.8.1-Ctcte9oFd5tFGoIV7u576g depends on
ansi-wl-pprint-0.6.8.1 which failed to install.
colour-2.3.4-9c0ktEQZfar3Wigr5kT6BU failed during the building phase. The
exception was:
ExitFailure 1
optparse-applicative-0.14.0.0-Iaq7kOKFg2Z4XsKvk269H6 depends on
optparse-applicative-0.14.0.0 which failed to install.
transformers-compat-0.5.1.4-HHfl4KyHCH71PMx2CRgdve failed during the building phase. The exception was:
ExitFailure 1

the error is incredibly cryptic

其实看起来很清楚:

error: #error __STDC_VERSION__ does not advertise C99 or later

C 头文件Stg.h 正在使用标准宏__STDC_VERSION__ 检查编译器是否支持C99(标准ISO C 的1999 版本)。由于未相应设置,编译器不符合 C99,C 源代码会触发错误。

基本上,Stg.h 拒绝使用甚至不支持 18 年前的 C 标准的 C 编译器进行编译。挺有道理的。

GCC 4.8 确实看起来很古老:最新的 GCC 是 7.1。如果不是最新版本,我会尝试将 GCC 升级到更新版本。


更新:正如 Keith Thompson 在下面指出的那样,GCC 4.8,尽管它已经很老了,但如果通过标志 -std=c99,则可以支持 C99。应该有某种方法可以指示 cabal 将此标志传递给 gcc,但我不记得如何。为此,应该有一些名为 cflags 的选项,somehwere.