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.

ildjarn
  • 62,044
  • 9
  • 127
  • 211
ribbonwind
  • 53
  • 1
  • 1
  • 5

1 Answers1

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.

Howard Hinnant
  • 206,506
  • 52
  • 449
  • 577
  • 1
    Great, thanks for that useful snippet. The answer is as I thought: "libstdc++" and "gnu++98". – ribbonwind Oct 12 '12 at 19:35
  • @ribbonwind that's strange; for me the result is libc++ and gnu++11. – bames53 Oct 14 '12 at 03: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. – Howard Hinnant Oct 14 '12 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? – Iulian Onofrei Sep 21 '16 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. – Howard Hinnant Sep 21 '16 at 16:55
  • @HowardHinnant, can you show me the command in order to run it against my project too? – Iulian Onofrei Sep 21 '16 at 17:06
  • @IulianOnofrei: Create a test.cpp that includes any standard header (e.g. ``). 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. – Howard Hinnant Sep 21 '16 at 17:15