c++0x进行编译,但eclipse编辑器错误,即使使用了-gnu++0x发现

c++0x compiles but eclipse editor errors even with -gnu++0x discovery

本文关键字:发现 -gnu++0x 错误 编辑器 编译 eclipse c++0x      更新时间:2023-10-16

我使用一些代码来使用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支持准备就绪。