在 Mac OS x 中制造期间出现错误未知类型名称"constexpr"

Error unknown type name 'constexpr' during make in mac os x

本文关键字:未知 错误 类型 constexpr OS Mac 制造      更新时间:2023-10-16

当我使用 scons 制作一些程序时,会发生类似这样的错误,

错误:未知类型名称"constexpr">

错误:预期的非限定 ID

我已经安装了xcode和xquartz最新版本。 这是我的Mac叮当版

Apple LLVM 版本 8.1.0 (clang-802.0.42( 目标:x86_64-苹果-达尔文16.6.0 螺纹型号:磅 InstalledDir:/applications/Xcode.app/Content/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

而且,为了以防万一,我附上了整个错误日志。

/Users/jeon.hk/Documents/geant4/geant4.10.3-install/bin/../include/Geant4/CLHEP/Units/SystemOfUnits.h:54:10: error: unknown type name 'constexpr'
static constexpr double     pi  = 3.1415;
^
/Users/jeon.hk/Documents/geant4/geant4.10.3-install/bin/../include/Geant4/CLHEP/Units/SystemOfUnits.h:54:20: error: expected unqualified-id
static constexpr double     pi  = 3.1415;
^
/Users/jeon.hk/Documents/geant4/geant4.10.3-install/bin/../include/Geant4/CLHEP/Units/SystemOfUnits.h:55:10: error: unknown type name 'constexpr'
static constexpr double  twopi  = 2*pi;
^
/Users/jeon.hk/Documents/geant4/geant4.10.3-install/bin/../include/Geant4/CLHEP/Units/SystemOfUnits.h:55:20: error: expected unqualified-id
static constexpr double  twopi  = 2*pi;
^
/Users/jeon.hk/Documents/geant4/geant4.10.3-install/bin/../include/Geant4/CLHEP/Units/SystemOfUnits.h:56:10: error: unknown type name 'constexpr'
static constexpr double halfpi  = pi/2;
^
/Users/jeon.hk/Documents/geant4/geant4.10.3-install/bin/../include/Geant4/CLHEP/Units/SystemOfUnits.h:56:20: error: expected unqualified-id
static constexpr double halfpi  = pi/2;
^
/Users/jeon.hk/Documents/geant4/geant4.10.3-install/bin/../include/Geant4/CLHEP/Units/SystemOfUnits.h:57:10: error: unknown type name 'constexpr'
static constexpr double     pi2 = pi*pi;
^
/Users/jeon.hk/Documents/geant4/geant4.10.3-install/bin/../include/Geant4/CLHEP/Units/SystemOfUnits.h:57:20: error: expected unqualified-id
static constexpr double     pi2 = pi*pi;
^
/Users/jeon.hk/Documents/geant4/geant4.10.3-install/bin/../include/Geant4/CLHEP/Units/SystemOfUnits.h:62:10: error: unknown type name 'constexpr'
static constexpr double millimeter  = 1.;
^
/Users/jeon.hk/Documents/geant4/geant4.10.3-install/bin/../include/Geant4/CLHEP/Units/SystemOfUnits.h:62:20: error: expected unqualified-id
static constexpr double millimeter  = 1.;
^
/Users/jeon.hk/Documents/geant4/geant4.10.3-install/bin/../include/Geant4/CLHEP/Units/SystemOfUnits.h:63:10: error: unknown type name 'constexpr'
static constexpr double millimeter2 = millimeter*millimeter;
^
/Users/jeon.hk/Documents/geant4/geant4.10.3-install/bin/../include/Geant4/CLHEP/Units/SystemOfUnits.h:63:20: error: expected unqualified-id
static constexpr double millimeter2 = millimeter*millimeter;
^
/Users/jeon.hk/Documents/geant4/geant4.10.3-install/bin/../include/Geant4/CLHEP/Units/SystemOfUnits.h:64:10: error: unknown type name 'constexpr'
static constexpr double millimeter3 = millimeter*millimeter*millimeter;
^
/Users/jeon.hk/Documents/geant4/geant4.10.3-install/bin/../include/Geant4/CLHEP/Units/SystemOfUnits.h:64:20: error: expected unqualified-id
static constexpr double millimeter3 = millimeter*millimeter*millimeter;
^
/Users/jeon.hk/Documents/geant4/geant4.10.3-install/bin/../include/Geant4/CLHEP/Units/SystemOfUnits.h:66:10: error: unknown type name 'constexpr'
static constexpr double centimeter  = 10.*millimeter;
^
/Users/jeon.hk/Documents/geant4/geant4.10.3-install/bin/../include/Geant4/CLHEP/Units/SystemOfUnits.h:66:20: error: expected unqualified-id
static constexpr double centimeter  = 10.*millimeter;
^
/Users/jeon.hk/Documents/geant4/geant4.10.3-install/bin/../include/Geant4/CLHEP/Units/SystemOfUnits.h:67:10: error: unknown type name 'constexpr'
static constexpr double centimeter2 = centimeter*centimeter;
^
/Users/jeon.hk/Documents/geant4/geant4.10.3-install/bin/../include/Geant4/CLHEP/Units/SystemOfUnits.h:67:20: error: expected unqualified-id
static constexpr double centimeter2 = centimeter*centimeter;
^
/Users/jeon.hk/Documents/geant4/geant4.10.3-install/bin/../include/Geant4/CLHEP/Units/SystemOfUnits.h:68:10: error: unknown type name 'constexpr'
static constexpr double centimeter3 = centimeter*centimeter*centimeter;
^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
scons: *** [build/macosx64/rat.o] Error 1 
scons: building terminated because of errors.

我真的非常感谢任何评论。

这个问题的正确答案是在启用 c++11 支持的情况下进行编译(对于 clang-std=c++11(,以便识别 constexpr 关键字。