3

What is the value of "Compiler Default" for "C++ Standard Library" and "C++ Language Dialect" in Xcode 4.5?

My guess is libstdc++ and GNU++98, but it would be nice to have clarification.

From the Xcode 4.5 release notes:

Projects created using this Xcode release use the new libc++ implementation of the standard C++ library. The libc++ library is available only on iOS 5.0 and later and OS X 10.7 and later. 12221787

To enable deployment on earlier releases of iOS and OS X in your project, set the C++ Standard Library build setting to libstdc++ (Gnu C++ standard library).

I notice that creating a new project explicitly sets GNU++11 and libc++, but "Compiler Default" is probably something else.

1 Answer 1

8

Here is the best way to find out:

 #include <iostream>

int main()
{
#ifdef _LIBCPP_VERSION
    std::cout << "Using libc++\n";
#else
    std::cout << "Using libstdc++\n";
#endif
#ifdef __GXX_EXPERIMENTAL_CXX0X__
#if __cplusplus == 1
    std::cout << "Language mode = gnu++11\n";
#else
    std::cout << "Language mode = c++11\n";
#endif
#else
#if __cplusplus == 1
    std::cout << "Language mode = gnu++98\n";
#else
    std::cout << "Language mode = c++98\n";
#endif
#endif
}

Just build a test project with the compiler defaults and run it.

7
  • 1
    Great, thanks for that useful snippet. The answer is as I thought: "libstdc++" and "gnu++98".
    – ribbonwind
    Oct 12, 2012 at 19:35
  • @ribbonwind that's strange; for me the result is libc++ and gnu++11.
    – bames53
    Oct 14, 2012 at 3:26
  • There is some confusion here as to what was asked and answered. I assumed that ribbonwind was asking what "compiler default" meant when chosen in the build settings. Others are asking/answering what the default build settings are. These are two different things. Oct 14, 2012 at 15:33
  • I get libstdc++ and gnu++98 even though I set the C++ Standard Library option to libc++ (...) in Xcode 8. Does these macros still apply? Sep 21, 2016 at 16:42
  • @IulianOnofrei: I just ran a HelloWorld with the Xcode 8 command line tools using -E -dM and it output #define _LIBCPP_VERSION 3700. I did not confirm that the IDE does not have a bug with the way it presents options in the GUI. Sep 21, 2016 at 16:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.