In Xcode 4.5, what is "Compiler Default" for "C++ Standard Library" and "C++ Language Dialect"?

10,954

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.

Share:
10,954
ribbonwind
Author by

ribbonwind

Updated on June 05, 2022

Comments

  • ribbonwind
    ribbonwind almost 2 years

    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.

  • ribbonwind
    ribbonwind over 11 years
    Great, thanks for that useful snippet. The answer is as I thought: "libstdc++" and "gnu++98".
  • bames53
    bames53 over 11 years
    @ribbonwind that's strange; for me the result is libc++ and gnu++11.
  • Howard Hinnant
    Howard Hinnant over 11 years
    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.
  • Iulian Onofrei
    Iulian Onofrei over 7 years
    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?
  • Howard Hinnant
    Howard Hinnant over 7 years
    @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.
  • Iulian Onofrei
    Iulian Onofrei over 7 years
    @HowardHinnant, can you show me the command in order to run it against my project too?
  • Howard Hinnant
    Howard Hinnant over 7 years
    @IulianOnofrei: Create a test.cpp that includes any standard header (e.g. <type_traits>). The compile with clang++ test.cpp -E -dM. I like to pipe that to my editor: clang++ test.cpp -E -dM | edit for easer searching. The -E says "preprocess only". The -dM says list all macro definitions.