void-pointer
void-pointer

Reputation: 14827

C++11 not Working with Macports gcc47

I recently installed Macports on my Macbook Pro, and installed the gcc47 port. After adding alias g++="g++-mp-4.7" to my .profile and ensuring that I was using g++-4.7, I attempted to build one of my projects that makes use of C++11. However, I receive this error:

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

I find this strange, since Macports built gcc with support for C++, so I would expect that C++11 should work without any problems. I have pasted the output from g++ -v below. Do you have any ideas as to why g++-mp-4.7 is not recognizing -std=c++11 as a valid option?

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) 

Upvotes: 1

Views: 2868

Answers (2)

dans3itz
dans3itz

Reputation: 1615

For future reference, if you install gcc_select you can do:

 sudo port select gcc mp-gcc47
 hash gcc

This should setup your Macports installed gcc; if you need to reset to Xcode's default, just rerun it with 'none'

EDIT: and Xcode 4.4.x comes with a decent build of Clang; if you install it and then from Preferences->Downloads: Command Line Tools click "Install"

Run clang as:

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

Note that if mp-gcc47 is not installed, you'll need to do this first:

 sudo port install mp-gcc47

To get a full list of available gcc ports:

 sudo port list | grep gcc | less

Upvotes: 3

void-pointer
void-pointer

Reputation: 14827

My problem was that since GNU Make executes commands in a different shell, alias g++="g++-mp-4.7" will have no effect on the commands executed by make.

Upvotes: 1

Related Questions