I wanted to compile C++11 source code within Mac Terminal but failed. I tried g++ -std=c++11
, g++ -std=c++0x
, g++ -std=gnu++11
and
XCode uses clang
and clang++
when compiling, not g++
(assuming you haven't customized things). Instead, try:
$ cat t.cpp
#include
int main()
{
int* p = nullptr;
std::cout << p << std::endl;
}
$ clang++ -std=c++11 -stdlib=libc++ t.cpp
$ ./a.out
0x0
Thanks to bames53's answer for pointing out that I had left out -stdlib=libc++
.
If you want to use some GNU extensions (and also use C++11), you can use -std=gnu++11
instead of -std=c++11
, which will turn on C++11 mode and also keep GNU extensions enabled.