C++0x 与 Qt Creator

标签 c++ qt c++11 mingw qt-creator

我正在尝试使用 Qt Creator 中的新 C++0x 功能在 Windows 下(Qt Creator 2.0.1)。

我读了线程 Configuring the GCC compiler switches in Qt, Qt Creator, and QMake 并将 QMAKE_CXXFLAGS += -std=c++0x 添加到 .pro 文件中。

Qt Creator 在这个简单的代码上给了我非常奇怪的错误:

#include <memory>

int main()
{
}

编译器错误:

'::swprintf' has not been declared

'::vswprintf' has not been declared

我尝试使用命令 g++ test.cpp --std=c++0x 从命令行编译我的代码并得到相同的错误。

那么 Qt 出了什么问题 MinGW编译器? Qt Creator 中是否可以使用 C++0x 功能?

最佳答案

首先,可能是库头不能正确表示它们的依赖关系。尝试添加 #include <cstdio>也许(不幸地)一个using namespace std;到您的文件顶部。

否则,似乎有几个人对 MinGW 和 swprintf 有问题。 This mailing list post建议添加:

#ifdef WIN32
#define swprintf _snwprintf
#endif

看看这是否能解决问题。 (您也希望它位于文件的最顶部。)

如果在您的源中添加随机定义对您来说是个坏主意,我建议使用 -D在 MinGW 上构建时,构建标志以有条件地注入(inject)上述定义。

另见 this short discussion MinGW 上的 swprintf 与其他编译器的区别。

最后,一切都失败了,this link似乎将问题归咎于启用 __STRICT_ANSI__ 的标志的问题。在 MinGW 中,并建议在其中一个 MinGW header 中注释掉几行以解决此问题。我建议添加一个更简单的 #ifndef __STRICT_ANSI__如果您决定使用此 hack,请围绕它们。

关于C++0x 与 Qt Creator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5003543/

相关文章:

c++ - fatal error LNK1104 : cannot open file "Debug/

c++ - 在 C++ 中 fork 和 kill 导致 ubuntu 崩溃

c++ - std::pair<_Ty1,_Ty2>::pair<_Ty1,_Ty2>& 无法转换参数

python - 实现 PySide 标注

python - 如何使用Qt Delegates进行自定义绘画?

python-3.x - 运行时错误 : Please destroy the QApplication singleton before creating a new QApplication instance

c++ - QObject::connect 和模板导致问题

c++ - Boost.asio 端点是否可以用于识别 UDP 连接的客户端?

c++ - 如何 typedef 模板类?

c++ - 这个尾随返回类型在 C++11 中合法吗?