I am trying to get C++11 features to compile on my Mac. I have tried two different things so far. First, the latest Xcode (4.2) claims to support “C++11 features” but when I try to compile this:
#include <iostream>
int main()
{
using namespace std;
int n = [] (int x, int y) { return x + y; }(5, 4);
cout << n << endl;
}
I get an error, “expected expression,” for the first bracket ([). I’m guessing lambda expressions are not included in the new C++11 features?
Then, as a work around I downloaded gcc 4.6 binaries from http://hpc.sourceforge.net/ but when I use gcc-4.6 (/usr/local/bin/gcc-4.6 -std=c++0x test.cpp) I get:
Undefined symbols for architecture x86_64:
"std::cout", referenced from:
_main in cctnMUFF.o
...
I’m thinking it’s an issue with not finding the standard library?
Thanks!
XCode 4.2 ships with a late Clang 2.9, patched by Apple. It does not support lambda’s nor uniform initializers. Clang 3.0 doesn’t either, so you’ll have to wait until at least Clang 3.1 (which is due in 6 months from now).
Alternatively, you could use Macports’ GCC 4.6 for lambda support.
UPDATE to your update: you need to link with
g++, or add-lstdc++manually.