1
votes

I'm having problems trying to compile this code:

int *array_aleatorio = new int[8]{0, 1, 2, 3, 4, 5, 6, 7};

This is the error that shows up:

main.cpp:315:38: error: expected ';' at end of declaration
int *array_aleatorio = new int[8]{0, 1, 2, 3, 4, 5, 6, 7};

One of my teammates told me this can be because I'm not using the correct compilator. He's using C++11 and it works. I've tried to install it without any success.

I'm using OSX 10.6.8 and Netbeans 7.3

I'm using clang++. enter image description here

I've tried this this solution by adding the -std=c++11 -stdlib=libc++ -Weverything line to the compiling properties of the project, but it's not working: enter image description here

This is the error that shows up when I try to execute it by adding the lines above.

clang++ -std=c++11 -stdlib=libc++ -Weverything -c -g -std=c++11
-stdlib=libc++ -Weverything -MMD -MP -MF build/Debug/GNU-MacOSX/main.o.d -o build/Debug/GNU-MacOSX/main.o
main.cpp clang: warning: argument unused during compilation:
'-std=c++11' clang: warning: argument unused during compilation:
'-stdlib=libc++' warning: unknown warning option '-Weverything'
[-Wunknown-warning-option] warning: unknown warning option
'-Weverything' [-Wunknown-warning-option] error: invalid value 'c++11'
in '-std=c++11'

Can someone tell me how to install C++11 in OSX? Thanks in advance.

2
Clang supports c++11 just fine. What version do you have? - Carl Norum
int array_aleatorio[] = {0, 1, 2, 3, 4, 5, 6, 7}; - fvu
I agree. new is looking completely pointless here. - chris

2 Answers

5
votes

Your Xcode is way out of date. Xcode 3.2.6 was released in 2011 and includes:

Apple clang version 1.7 (tags/Apple/clang-77) (based on LLVM 2.9svn)

Based on the release date, it's not really surprising that it doesn't have C++11 support.

You want to get Xcode 4.6 which includes:

Apple LLVM version 4.2 (clang-425.0.28) (based on LLVM 3.2svn)

You might need to update your OS, too - 10.6.8 is a couple of years old, too.

1
votes

The last supported version(that comes with xcode) of clang on snow leopard is not c++11 compatible, but you can install macports ( http://www.macports.org/install.php ) and with the help of the console you can install a newer version of clang, "sudo port install clang-3.2" for example.

The folder in which clang is installed can be found with "whereis clang-3.2"