In Xcode 4.5, what is “Compiler Default” for “C++

2019-02-03 20:00发布

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条回答
在下西门庆
2楼-- · 2019-02-03 20:41

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.

查看更多
登录 后发表回答