C ++ 11不能使用Macports gcc47

时间:2012-08-11 22:24:29

标签: c++ c++11 g++ macports

我最近在Macbook Pro上安装了Macports,并安装了gcc47端口。将alias g++="g++-mp-4.7"添加到.profile并确保我使用g++-4.7后,我尝试构建一个使用C ++ 11的项目。但是,我收到此错误:

cc1plus: error: unrecognized command line option "-std=c++11"

我发现这很奇怪,因为Macports构建了支持C ++的gcc,所以我希望C ++ 11应该没有任何问题。我已粘贴下面g++ -v的输出。您对g++-mp-4.7未将-std=c++11视为有效选项的原因有任何想法吗?

COLLECT_GCC=g++-mp-4.7
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin12/4.7.1/lto-wrapper
Target: x86_64-apple-darwin12
Configured with: ../gcc-4.7.1/configure --prefix=/opt/local --build=x86_64-apple-darwin12 --enable-languages=c,c++,objc,obj-c++,lto,fortran,java --libdir=/opt/local/lib/gcc47 --includedir=/opt/local/include/gcc47 --infodir=/opt/local/share/info --mandir=/opt/local/share/man --datarootdir=/opt/local/share/gcc-4.7 --with-libiconv-prefix=/opt/local --with-local-prefix=/opt/local --with-system-zlib --disable-nls --program-suffix=-mp-4.7 --with-gxx-include-dir=/opt/local/include/gcc47/c++/ --with-gmp=/opt/local --with-mpfr=/opt/local --with-mpc=/opt/local --with-ppl=/opt/local --with-cloog=/opt/local --enable-cloog-backend=isl --enable-stage1-checking --disable-multilib --enable-lto --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld --with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket --disable-ppl-version-check --with-pkgversion='MacPorts gcc47 4.7.1_2'
Thread model: posix
gcc version 4.7.1 (MacPorts gcc47 4.7.1_2) 

2 个答案:

答案 0 :(得分:3)

为了将来参考,如果你安装gcc_select,你可以这样做:

 sudo port select gcc mp-gcc47
 hash gcc

这应该设置你的Macports安装gcc;如果你需要重置为Xcode的默认值,只需用'none'重新运行

编辑:Xcode 4.4.x带有一个体面的Clang;如果您安装它,然后从Preferences->下载:命令行工具单击“安装”

将clang运行为:

clang++ -std=c++11 -stdlib=libc++ ...

请注意,如果未安装mp-gcc47,则需要先执行此操作:

 sudo port install mp-gcc47

获取可用gcc端口的完整列表:

 sudo port list | grep gcc | less

答案 1 :(得分:1)

我的问题是,由于GNU Make在不同的shell中执行命令,alias g++="g++-mp-4.7"make执行的命令没有影响。