1

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.

Community
  • 1
  • 1
Avión
  • 7,963
  • 11
  • 64
  • 105

2 Answers2

5

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.

Carl Norum
  • 219,201
  • 40
  • 422
  • 469
  • I cant update Xcode because as you said, it needs a newer OSX version, and for several reasons, it's impossible to do that. – Avión Jul 08 '13 at 16:58
  • 1
    Impossible? Why? Anyway, you can go get the clang sources and build your own if you're really stuck. – Carl Norum Jul 08 '13 at 16:59
  • Due to some HD redimensions if I want to update the OSX I've to do it by clean installation instead of updating the OSX normally. And for that I need to backup all the data and I don't have the time to do that now. I'll try to do what you're saying. – Avión Jul 08 '13 at 17:05
  • 1. You should probably be backing up regularly. 2. Why can't you install the new OS on an external drive then? – Carl Norum Jul 08 '13 at 17:06
  • I was simply looking for a solution that avoids any OS update. – Avión Jul 08 '13 at 17:09
  • 1
    @Borja I am currently testing the use of the open source MacPorts on Snow Leopard 10.6.8 to obtain the clang++ 3.3 compiler. I have a slow (by today's high speed expectations) Internet connection. It has been about 2 hours downloading the files and installing normally. When it is all complete and running properly, I will post an answer with the details. Hopefully this is not too late to be useful. – CPlusPlus OOA and D Mar 04 '14 at 23:26
  • @CPlusPlusOOAandD Nevermind. I had to change all my code to `Python` so don't worry. Anyways, thanks for the interest. – Avión Mar 05 '14 at 09:35
  • 1
    @Borja Well, if you would like to review the MacPorts usage details, check out my answer posted for [Problems throwing and catching exceptions on OS X with -fno-rtti](http://stackoverflow.com/questions/21737201/problems-throwing-and-catching-exceptions-on-os-x-with-fno-rtti/22135849#comment33612941_22135849). My post starts with the words: *Start Edit March 4, 2014* – CPlusPlus OOA and D Mar 05 '14 at 15:01
1

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"