-std=gnu++11 导致的问题

来源:互联网 发布:js 字符串操作 编辑:程序博客网 时间:2024/06/07 15:52

今天打算在自己新的C++工程中启用C++11, 到时候了,该全面升级了。

编译器是GCC4.8.1, 查看官方文档:http://gcc.gnu.org/onlinedocs/gcc-4.8.1/libstdc++/manual/manual/using.html#manual.intro.using.flags

看到可以使用的选项是-std=gnu++11,结果编译报错,都是:

/usr/bin/../lib/gcc/x86_64-linux-gnu/4.8/../../../../include/c++/4.8/type_traits:268:39: error: use of undeclared identifier '__float128'    struct __is_floating_point_helper<__float128>

打开type_traits文件,找到268行左右的代码:

#if !defined(__STRICT_ANSI__) && defined(_GLIBCXX_USE_FLOAT128)  template<>    struct __is_floating_point_helper<__float128>    : public true_type { };#endif

根据Google的结果,有个解决方案:

一是换用--std=c++11,问题解决。

二是使用__STRCT_ANSI__

编译选项中添加了-D__STRICT_ANSI__后,果然问题解决。


另外,安装了clang3.2后,由于兼容gcc所有参数,编译时只需要将c++命令换成clang++即可。都知道clang编译快,报错友好。等到发布的时候,再换成gcc,获得更快的性能。还是不错的用法。

原创粉丝点击