在使用Qt Creator(mingw 4.8和Qt 5.3)中使用c++11特性时出现奇怪的错误。

3

我希望在Qt Creator项目中使用C++11。我已经尝试通过将以下内容之一添加到.pro文件中来添加C++11支持:

 CONFIG += c++11

或者

 QMAKE_CXXFLAGS += -std=c++11

但是这些方法都对我无效,在将它们添加到.pro文件后,编译器(mingw 4.8)会给我很多错误,例如:
C:/Qt/Qt5.3.2/Tools/mingw482_32/i686-w64-mingw32/include/c++/cstdint:48:11: error: '::int8_t' has not been declared using ::int8_t; ^ C:/Qt/Qt5.3.2/Tools/mingw482_32/i686-w64-mingw32/include/c++/cstdint:49:11: error: '::int16_t' has not been declared using ::int16_t; ^ C:/Qt/Qt5.3.2/Tools/mingw482_32/i686-w64-mingw32/include/c++/cstdint:50:11: error: '::int32_t' has not been declared using ::int32_t; ^ C:/Qt/Qt5.3.2/Tools/mingw482_32/i686-w64-mingw32/include/c++/cstdint:51:11: error: '::int64_t' has not been declared using ::int64_t; ^ C:/Qt/Qt5.3.2/Tools/mingw482_32/i686-w64-mingw32/include/c++/cstdint:53:11: error: '::int_fast8_t' has not been declared using ::int_fast8_t;
问题出在哪里?!
2个回答

1
如果您正在使用cstdint,则需要提供这些类型的using语句。
using ::int8_t;
using ::int16_t;
using ::int32_t;
using ::int64_t;
using ::int_fast8_t;

将(以及其他报告缺失的内容)添加到源文件中,这些错误发生在这些文件中。请参阅此处了解更多相关信息。

因为答案是错误的所以被踩了。问题中的引用清楚地显示错误来自于<cstdint>内部,确切地说是在该头文件中相应的using语句中。关于链接的答案;MinGW有许多实现<cstdint>的方式,其中只包括C头文件,污染全局命名空间,然后使用using指令将其提升到std::命名空间中。问题在于,某种方式下C头文件没有定义这些类型。6年后我遇到了同样的问题,希望能得到正确的答案。 - burnpanck

0

这个错误最常见的情况是你在自己的命名空间中包含标准库头文件。(不要这样做;)

例如:

namespace my_space {
   #include <cstdint>
}

https://godbolt.org/z/bP7TnWP1s


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接