I'm having some trouble with C++11 in Xcode - c++

I'm a Mac OS X Lion user who uses Xcode for C++, and it appears that no updates are available for Xcode. I do not appear to be able to compile C++11-exclusive code, but for whatever reason, I thought Apple had gotten C++11 pretty much implemented. And yes, I do have support for Command Line Tools.
Then again, that might just be me. If so, is there any sort of IDE that supports C++11, or any way to upgrade?

I use Xcode and set the following settings:
C++ language dialect: C++11 or GNU++11
C++ Standart Library: libc++ (LLVM C++ standart library with C++11 support)
Xcode version: 4.3.2

If you're using Xcode 4.3 there are several relevant project settings you need to use C++11 features. The first is to use the clang compiler. Something like
GCC_VERSION = com.apple.compilers.llvm.clang.1_0
in your .xcconfig will set it, or you can use the GUI.
Next, you need to tell LLVM which C++ standard to use:
CLANG_CXX_LANGUAGE_STANDARD = gnu++11
This will make language features like range based for, delegated constructors, etc. available.
Finally, if you want to use C++11 STL features (such as std::unordered_map) you need to use the libc++ STL:
CLANG_CXX_LIBRARY = libc++

On XCode 5 / opencv 2.4.9, I can select:
And it builds without error.
If i set the libc++ without specifying C++ Language Dialect then I get same issue as OP

Related

std::vector autocomplete not working inside Xcode 6.6

I'm just trying to build a very simple program that uses std::vector in Xcode.
Here are my configuration settings -
Apple LLVM 6.1 - Language C++ C++ Language dialect =
GNU++11[-std=gnu++11] C++ Standard Library = libc++ (LLVM C++
standard library with C++11 support)
Code like this below works fine, I can use the std:: library as I need it. However, the ctrl+space autocomplete doesn't seem to work for some things. Like for example, it doesn't give me std::vector as an suggestion
std::vector<double> measurements
Here are my header search paths
-/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include
-/usr/local/include
What could I be doing wrong? The code builds and runs fine!

xcode 5.1.1 complaining: ISO C++11 does not allow access declarations

I have a project that builds and runs fine on Xcode 4.6.3.
But it does not on Xcode 5.1.1.
This is the unique error I get, hundred times.
"ISO C++11 does not allow access declarations; use using declarations instead".
Basically it wants me to go from:
typedef Something<MType>::Index Index;
Something<MType>::N;
to
typedef Something<MType>::Index Index;
using Something<MType>::N;
Why is it?
If I "solve it" as Xcode says, the final app behaves randomly.
Is it possible to build this project on Xcode 5.1.1 as if it were 4.6.3? (in other words: changing the project settings, but keeping the code intact)
AFAIS, the C++ flags have the same value for both Xcode versions.
C Language Dialect = GNU99 [-std=gnu99]
C++ Language Dialect = GNU++11 [-std=gnu++11]
C++ standard library = libc++ (LLVM C++ standard library with C++11 support)
It looks like a deliberate change to the compiler:
http://llvm.org/viewvc/llvm-project?view=revision&revision=183882
The standards body says: "Access declarations were deprecated in the 1998 standard and have no benefits over using-declarations. They should be removed in C++0x."
And I can't find anyway of reverting to an older (non-standard compliant) C++11 behaviour. I was half expecting this to work:
clang -std=c++0x
But, it doesn't. You get the same error.
Including using looks like the right fix. I've just done some testing here and it does what it says on the tin.
Probably not what you want to hear, but I think you should look into why the code behaves randomly when you use the using directive.

Xcode 5.1 compile against C++98, avoid C++11 features

I'm currently working on a project that primarily uses C++98 as a coding standard for backwards compatibility. I'm working on OSX10.9 mavericks and have compiled all dependencies against libc++.
I would like to configure Xcode in such a way that it gives me a warning or doesn't compile when I use C++11 language features.
Compiling with the -std=c++98 flag didn't show any errors/notifications concerning the use of C++11 features.
I didn't enable the "Using C++11 extensions in earlier versions of C++"-warning. Now XCode will show me a compiler warning if I use C++11 features.
To check if I use library features from the new standard I still have to link libstdc++.

Xcode support of lambda functions

I have a program coded in VS that I'm trying to port over to Xcode. There are several issues I have ran into including use of lambda functions. Since Xcode uses gcc 4.2 and thus doesn't support C++11, will I not be able to use any lambda functions?
If I want to work on the code from my laptop without rewriting much of the code, will I have to install gcc 4.6 and compile using the terminal?
You have few options:
Re-write your code to the C++ 2003 standard.
Install GCC that supports C++11 features being used in the code and not use Xcode (you may use other IDEs, for example QtCreator or Eclipse CDT).
Wait for Xcode that comes with LLVM C++ compiler that supports C++11 features.

Can I use C++11 with Xcode?

I am considering the use of some C++11 features (like auto for instance) in some cross-platform projects (Windows+Mac). On Windows, Visual Studio supports parts of the upcoming C++11 standard that would allow me to simplify parts of the code base so naturally I would be interested in starting to use these features.
But as far as I am aware, the current XCode version (3.2.4 + GCC 4.2) does not support any C++11 features at all. Can I upgrade the GCC version or the CLang version somehow? Or should I just bite my tongue and wait for Apple to package a new version sometime in the future?
Xcode 4.2 had finally added support for C++0X:
In the project build settings screen, switch on "All" options.
In the "Build Options" section, set compiler to "Apple LLVM compiler 3.0".
Scroll down to "Apple LLVM Compiler 3.0 - Language" section and set "C++ Language Dialect" to "C++0X" and "C++ Standard Library" to "libc++".
The std::move(), move constructor and R-Value reference are known to work as expected, and I'm testing on the std::thread and std::atomic.
======= Update 2012: =======
Start with Clang - Many C++11 features are now available in Clang. It's included with Xcode.
======= Original answer from Jan 2011: =======
intel's compiler may be the cleanest way to go at this time.
http://software.intel.com/en-us/articles/intel-composer-xe/
clang's promising, but not particularly stable or featured wrt c++0x features. c++ is still very new for clang.
gcc: relatively mature, but you'll have to write and maintain your compiler plugins for xcode.
you can also specify custom scripts, but that is a pain to maintain... unless you go all out and create an adaptor tool.
Xcode uses the GCC or the Clang C++ compilers. Any features supported by those compilers are fair game. GCC's C++ compatibility page is here and the Clang C++ compatibility page is here.
I've found auto, decltype(), range based "for (:)" work in a cross platform project (LLVM for MacOSX,iOS, gcc/linux, MSVC 10/windows).
lambdas & variadic macros don't appear to work under LLVM yet sadly.