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++.
Related
I purchased a book recently entitled beginning C++20. I was looking to begin learning c++ though I now realize that I can't find a compiler that can run the code in the book as I get an error since the compiler I'm using (xcode) does not support c++ 20. I'm wondering if there are any compilers that I can run on my mac that support c++20.
gcc version 8 and up supports some of C++20; you can try using that.
It should also be noted that Xcode isn't a compiler, but instead an IDE that should be using clang as the actual compiler. Clang also currently has support for some of the C++ 20 features. To use them the -std=c++20 flag will still be needed.
Here can you find the currently implemented feature support of the GCC compiler of the C++20 specification:
GCC Link
But you need to enable it in your console command or add this to your toolchain: "-std=c++20"
Given
Cross-platform C++ project that has to build on some ancient windows mobile platforms. However the development is done with GCC.
Problem
Every time that C++11 feature is used it will build locally but fail on the build server (mobile windows).
Question
Is it possible to configure GCC to somehow warn if C++11 feature is used in our code-base (excluding other source-dependencies).
What have you tried?
I know about using -std=c++98 -pedantic, but:
I would like to use the latest compiler standard on Linux platform
There are some linux-only third-party dependencies (build from the source) that require C++11
Build the code you need to be C++98 compatible using C++98 flags.
Build the code you need to be C++11 compatible using C++11 flags.
Examine the documentation of the compiler and standard library used to ensure ABI compatibility between code built with C++98 and C++11; you may have to (for example) use C++98 strings in your C++11 code in order to have ABI compatibility, assuming you pass std::strings between the C++98 and C++11 code bases.
You cannot both use C++11 and not use C++11 when building the same file, unless you build it twice. Which is also an option; build the C++98 compatible stuff twice, once with C++latest and once with C++98. Throw away the C++98 build after halting on errors and warnings.
I am having trouble understanding the different compilers that are available to me.
I mainly use Xcode for writing and compiling, and in Xcode's preferences, there are all of these options for C++ compilation:
C++ Language Dialect:
C++98[-std=c++98] through C++14[-std=c++14]
GNU++98[-std=gnu++98] through GNU++14[-std=gnu++14]
C++ Standard Library:
libstdc++ (GNU C++ standard library)
libc++ (LLVM C++ standard library with C++11 support)
Can someone explain what exactly all of that ^ is?
I understand that (and correct me if I'm wrong), that apple no longer distributes GCC with Xcode and use Clang instead?
If that were the case, then why does Xcode have the option for GNU C++ standard library? Doesn't GNU make GCC?
What compiler is invoked when I run C++ code in my local terminal with g++ filename.cpp?
Is there any way to make sure that this g++ "compiler" is up to date?
What's the difference between compiling with g++ in the terminal and using Xcode?
Also, what would be the difference if I tried running C++ programs with Clang?
My class requires us to test our programs on the department's server's compiler via ssh from my terminal. The server is a Unix machine and I know that its compiler is GNU's GCC compiler and we also access it using g++. Does this mean that the local g++ in my terminal is also GCC?
edit: Grammar
1.
C++ language dialect
C++98[-std=c++98] through C++14[-std=c++14]
GNU++98[-std=gnu++98] through GNU++14[-std=gnu++14]
The C++ language has evolved over time. These are the various versions of the language that are available to you. If you have to be compatible with something old, you might be forced to use an old one. Otherwise you'd probably want ot use the newest available, which is c++14 in the list above. 14 stands for 2014, 98 for 1998 - it is supposed to represent the year that version of the standard was blessed.
In addition to standard C++ there are non-standard extensions. Gnu is a compiler "manufacturer", the "GNU" above is the non-stanadard extensions as specified by GNU for a particular documented version.
C++ Standard Library:
libstdc++ (GNU C++ standard library)
libc++ (LLVM C++ standard library with C++11 support)
In addition to the base language, the standard library is also a part of the standard. These are two different implementations of the standard library. The first is by GNU, the second by llvm. llvm are a different compiler manufacturer.
On osx you'd probably use libc++ as I believe the llvm compiler (clang++) is now standard there. The llvm compiler will support the gnu extensions if you need them. You probably don't. Just use the latest version of whatever is default.
Yes
two different pieces, the compiler and the standard library. You can use clang++ with libstd++
g++ -v will tell you
not really. Update xcode to the newest or start looking at homebrew or ports to get the latest and greatest they package of whatever compiler you like.
Probably the same compiler, you can set it either to point at any compiler you have installed. So what each points at is your choice.
both g++ and clang++ are standards compliant. You're unlikely to notice much difference. They will complile the same source files into equivalent binaries.
run g++ -v in any terminal to see exactly what it is.
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
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.