【问题标题】:Qt 5.1 Beta Error using std::atomic c++11 feature使用 std::atomic c++11 功能的 Qt 5.1 Beta 错误
【发布时间】:2013-05-22 21:02:45
【问题描述】:

我刚刚开始使用 QT,并且仍然熟悉编译过程。目前,我正在尝试将现有的 QT 项目移植到 Mac。此应用可在 Linux 和 Windows 上编译和运行。

当我在 Mac OSX 10.8.2 上编译项目时,我收到了这个与 c++11 相关的错误,

#include ../xxx/pch.h:71:10: fatal error: 'atomic' file not found
#include <atomic>
^
1 error generated.
make[1]: *** [debug/xxx/objective-c++.pch] Error 1
make: *** [debug] Error 2
11:32:01: The process "/usr/bin/make" exited with code 2.
Error while building/deploying project xxx (kit: Qt5.1.0)
When executing step 'Make'

我在 .pro 文件中包含以下标志以启用 c++11,

QMAKE_CXXFLAGS += -std=c++11

CONFIG += c++11

我正在使用预构建的 QT5.1Beta 包 (Clang) 构建项目,我相信它已启用 c++11。

我在以下位置看到原子标头 /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/c++/v1/atomic 并在 /usr/lib/c++/v1/atomic

我尝试通过包含完整路径进行测试, /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr//lib/c++/v1/atomic

我收到以下错误,

In file included from ../xxx/pch.h:71:
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/c++/v1/atomic:535:2: 
error: atomic is not implemented

In file included from ../xxx/pch.h:124:
../../../yyy.h:308:12: error: no type named 'atomic' in namespace 'std'
std::atomic<bool> m_signaled;

我在这里错过了什么?

【问题讨论】:

  • 您尝试使用哪个编译器版本和标准库版本?即你安装了哪个?
  • 我使用 clang 构建项目。我安装了最新版本的 Xcode 4.6.2 和命令行工具。 $ c++ -v Apple LLVM 版本 4.2 (clang-425.0.28) (基于 LLVM 3.2svn) 目标:x86_64-apple-darwin12.2.1 线程模型:posix
  • 我使用 QT Creator 构建项目。使用的编译器是通过安装 Xcode 命令行工具获得的 Clang。

标签: c++ macos qt c++11 clang


【解决方案1】:

也添加

macx:QMAKE_CXXFLAGS += -stdlib=libc++
macx:QMAKE_LFLAGS += -stdlib=libc++

【讨论】:

  • 我尝试添加这些标志,但仍然遇到同样的错误。附加说明:我正在编译的项目有超过 50 个 cpp 源文件。我用一个简单的示例应用程序进行了测试。我试图找出区别。仅当从预编译的标头中包含 时,我才会收到此错误。 ---------- pch.h --------- #ifndef PCH_H #define PCH_H //Qt #include #include #endif ------- ----------------- 当“#include ”直接添加到cpp源文件时,示例应用程序编译并运行没有错误。
【解决方案2】:

也许有点晚了,但我使用-std=gnu++0x 标志修复了它

【讨论】:

  • -std=c++11
猜你喜欢
  • 2014-10-01
  • 1970-01-01
  • 1970-01-01
  • 2016-01-02
  • 2012-03-22
  • 2013-07-28
  • 2019-11-11
  • 2013-07-01
  • 1970-01-01
相关资源
最近更新 更多