简体   繁体   English

clang不知道std :: atomic_bool,但是XCode确实如此

[英]clang doesn't know std::atomic_bool, but XCode does

I'm trying to compile C++11 code that declares a variable of type std::atomic_bool. 我正在尝试编译声明类型为std :: atomic_bool的变量的C ++ 11代码。 This is on Mac OS 10.8.2 with clang: 这是在Mac OS 10.8.2上使用clang:

clang --version
Apple clang version 4.1 (tags/Apple/clang-421.11.66) (based on LLVM 3.1svn)
Target: x86_64-apple-darwin12.2.0
Thread model: posix

clang complains about std::atomic_bool: clang抱怨std :: atomic_bool:

clang++ -c -stdlib=libc++ -msse4 -std=c++11 -Wno-unused-parameter -I. -o query.o query.cpp
In file included from query.cpp:1:
[...]
./threadutils.h:33:10: error: no type named 'atomic_bool' in namespace 'std'; did you mean 'atomic_long'?
    std::atomic_bool work;

However, the same file compiles fine in an XCode project using the same compiler. 但是,使用相同的编译器在XCode项目中编译相同的文件。 So I assume I'm missing something in my manual compiler invocation. 所以我假设我在手动编译器调用中遗​​漏了一些东西。

I tried a few variations such as -std=c++0x and -std=gnu++11 , to no avail. 我尝试了一些变体,如-std=c++0x-std=gnu++11 ,但无济于事。

I figured it out. 我想到了。 Unfortunately I planted a false flag into my question: it didn't work in XCode either, I had a different version of the source file imported there. 不幸的是,我在我的问题中设置了一个错误的标志:它在XCode中也不起作用,我在那里导入了不同版本的源文件。

The problem was that C++11 defines "a named type atomic_bool corresponding to the specified atomic<bool> ", but clang doesn't support that . 问题是C ++ 11定义了“与指定的atomic<bool>对应的命名类型atomic_bool ”,但是clang不支持它

Renaming the type from atomic_bool to atomic<bool> fixed it. 将类型从atomic_bool重命名为atomic<bool>修复它。

I found the same problem. 我发现了同样的问题。 In my case I resolved it by including atomic: 在我的情况下,我通过包含原子来解决它:

#include <atomic>
static std::atomic_bool varname;

After this, I could call g++ with std=c++11 on a Linux (Ubuntu) as well as compile on XCode. 在此之后,我可以在Linux(Ubuntu)上使用std = c ++ 11调用g ++以及在XCode上编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM