当我使用scons制作一些程序时,会发生错误,如
错误:未知类型名称' constexpr'
错误:预期的unqualified-id
我已经安装了xcode和xquartz最新版本。 这是我的mac clang版本
Apple LLVM版本8.1.0(clang-802.0.42) 目标:x86_64-apple-darwin16.6.0 线程模型:posix InstalledDir:/Applications/Xcode.app/Contents/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.
我真的非常感谢您的评论。
答案 0 :(得分:6)
这个问题的正确答案是在启用c ++ 11支持的情况下编译(对于clang -std = c ++ 11),以便识别constexpr关键字。