我有一个使用一些 c++11 特性的 eclipse c++ 项目。它使用 cmake 进行构建,因此它在 Eclipse 中设置为具有现有 makefile 的项目。
无论是在 eclipse 中还是从命令行中,它都可以很好地构建 makefile。但是我得到 atomic_bool
的语法错误说符号无法解析。我添加了 -std=c++11
在“C/C++ General -> Preprocessor Include Pattern -> Providers -> CDT GCC Built-in Compiler Settings”下,我将 eclipse 中的工具链设置为 MacOSX GCC。
注意:其他 c++11 东西,如 thread
或 shared_ptr
不要给出任何语法错误。
错误来自 <atomic>
有预处理器的标题 if
声明
#if !__has_feature(cxx_atomic)
#error <atomic> is not implemented
#else
...
#else 下面的所有内容都是灰色的。显然__has_feature(cxx_atomic)
根据 eclipse 评估为 0。但是,如果我从命令行检查它,它会显示它的计算结果应该为真。
$ echo '__has_feature(cxx_atomic)' | g++ -x c++ -std=c++11 -E -
# 1 "<stdin>"
# 1 "<built-in>" 1
# 1 "<built-in>" 3
# 188 "<built-in>" 3
# 1 "<command line>" 1
# 1 "<built-in>" 2
# 1 "<stdin>" 2
1
为什么 __has_feature(cxx_atomic)
在 Eclipse 中评估为 false 但如果我检查编译器本身则不是?
最佳答案
尝试启用“构建输出解析器”。 http://www.eclipse.org/forums/index.php/t/501479/
关于c++ - 为什么 Eclipse 认为 clang 不支持 std::atomic,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22673946/