在 Xcode 4.5 中,“C++ 标准库”和“C++ 语言方言”的“编译器默认值”是什么?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12865226/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
In Xcode 4.5, what is "Compiler Default" for "C++ Standard Library" and "C++ Language Dialect"?
提问by ribbonwind
What is the value of "Compiler Default" for "C++ Standard Library" and "C++ Language Dialect" in Xcode 4.5?
Xcode 4.5 中“C++ 标准库”和“C++ 语言方言”的“编译器默认值”的值是多少?
My guess is libstdc++ and GNU++98, but it would be nice to have clarification.
我的猜测是 libstdc++ 和 GNU++98,但最好能得到澄清。
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).
使用此 Xcode 版本创建的项目使用标准 C++ 库的新 libc++ 实现。libc++ 库仅在 iOS 5.0 及更高版本和 OS X 10.7 及更高版本上可用。12221787
要在项目中启用较早版本的 iOS 和 OS X 上的部署,请将 C++ 标准库构建设置设置为 libstdc++(Gnu C++ 标准库)。
I notice that creating a new project explicitly sets GNU++11 and libc++, but "Compiler Default" is probably something else.
我注意到创建一个新项目明确设置了 GNU++11 和 libc++,但“编译器默认”可能是别的东西。
回答by Howard Hinnant
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.
只需使用编译器默认值构建一个测试项目并运行它。