c++0x进行编译,但eclipse编辑器错误,即使使用了-gnu++0x发现
c++0x compiles but eclipse editor errors even with -gnu++0x discovery
我使用一些代码来使用std::chrono::high_resolution_clock报告任务的持续时间。。。c++0x的一部分。
我可以使用-gnu++0x标志在eclipsecdt中成功地编译c++0x特性。尽管编译成功,但编辑器似乎没有意识到c++0x,即它显示了我代码中任何c++0xs功能的错误。我通过在项目发现选项中添加-gnu++0x标志来解决这个问题。注意:在进行另一次编译并重新生成索引之前,不会显示已修复。。。
-E-p-v-dD"${plugin_state_location}/specs.cpp"-std=gnu++0x
我仍然有最后一个编辑器错误,我无法摆脱"Symbol'duration_cast'无法解决"(我有一张照片,但新用户无法发布照片)
有人知道怎么解决这个问题吗?这是代码:
#ifndef _scoped_timer_h_
#define _scoped_timer_h_
#include <iostream>
#include <chrono>
#include "boost/noncopyable.hpp"
#include "boost/format.hpp"
using namespace std::chrono;
// Utility class for timing and logging rates
// (ie "things-per-second").
// NB _any_ destructor invokation (including early return
// from a function or exception throw) will trigger an
// output which will assume that whatever is being measured
// has completed successfully and fully.
class scoped_timer : boost::noncopyable
{
public:
scoped_timer(
const std::string& what,
const std::string& units,
double n
)
:_what(what)
,_units(units)
,_how_many(n)
,_start(high_resolution_clock::now())
{}
~scoped_timer() {
high_resolution_clock::time_point stop = high_resolution_clock::now();
const double t = 1e-9 * duration_cast<nanoseconds>(stop-_start).count();
std::cout << (
boost::format(
"%1%: %|2$-5.3g| %|3$|/s (%|4$-5.3g|s)"
) % _what % (_how_many/t) % _units % t
) << std::endl;
}
private:
const std::string _what;
const std::string _units;
const double _how_many;
const high_resolution_clock::time_point _start;
};
#endif
对于eclipse中的chrono,您应该添加这些符号
_GLIBCXX_USE_C99_STDINT_TR1
和
__cplusplus = 201103L
如何添加:
项目属性->C/C++通用->路径和符号->符号(选项卡)->GNU C++->然后单击添加。
请记住将__cplusplus
与值201103L
相加
Eclipse有自己的解析器。该解析器无法处理c++11(c++0x)特性。因此,您必须等待eclipse解析器中的c++11支持准备就绪。
相关文章:
- 使用 Powershell 命令将 cpp 文件的文件夹编译为 GNU 的 g++
- 如何使用 gnu gcc 标志 -mpc32、-mpc64 和 -mpc80?
- 定义宏以将前缀 0x 添加到十六进制字符串文本
- 0x%08lx 格式说明符在 printf 语句到 cout
- CTest 项目目录.未发现任何测试
- 请发现它在 dev 中工作的错误,但在 hackerrank 中不起作用
- 我的 c++ 程序似乎没有发现字符串和我拥有但输入使用 getline 的变量之间的比较
- Nanoflann发现邻居提出段错误
- 我在玩VS2017时发现了一些东西
- 在使用另一个类"friend"函数时无法发现错误C++
- G-WAN cc1plus:错误:无法识别的命令行选项"-std=gnu++0x"
- 使用-std=gnu++11时发现了哪些已知的性能差异
- 尝试通过CGAL_CXX_FLAGS设置 --std=c++0x 或 -std=gnu++0x 会忽略值
- 适用于 MacOS 的"-std=gnu++0x"选项
- 启用-std=c++0x或-std=gnu++0x编译器选项
- G++ 4.6 -std=gnu++0x:静态局部变量构造函数调用计时和线程安全
- 警告:扩展初始值设定项列表仅适用于-std=c++0x或-std=gnu++0x
- g++ 4.4.7 -std=gnu++0x 应该编译"for each"结构吗?
- c++0x进行编译,但eclipse编辑器错误,即使使用了-gnu++0x发现
- Unordered_multimap在gnu++11和c++ ++0x中的不同行为