Search code examples
c++eclipse-cdt

C++ Expressions like cerr, exit, string not recognized in eclipse c++ IDE windows


I am using eclipse C/C++ IDE and I have the following code:

using namespace std;
using namespace g2o;
using namespace Eigen;

// sort according to max id, dimension
 struct IncrementalEdgesCompare {
 bool operator()(SparseOptimizer::Edge* const & e1, SparseOptimizer::Edge*  const & e2)
{
const SparseOptimizer::Vertex* to1 = static_cast<const       SparseOptimizer::Vertex*>(e1->vertices()[1]);
const SparseOptimizer::Vertex* to2 = static_cast<const SparseOptimizer::Vertex*>(e2->vertices()[1]);

int i11 = e1->vertices()[0]->id(), i12 = e1->vertices()[1]->id();
if (i11 > i12){
  swap(i11, i12);
}
int i21 = e2->vertices()[0]->id(), i22 = e2->vertices()[1]->id();
if (i21 > i22){
  swap(i21, i22);
}
if (i12 < i22)
  return true;
if (i12 > i22)
  return false;
// push the odometry to be the first
return to1->dimension() > to2->dimension();
  }
 };

 void sigquit_handler(int sig)
 {
 if (sig == SIGINT) {
  hasToStop = 1;
  static int cnt = 0;
  if (cnt++ == 2) {
  cerr << __PRETTY_FUNCTION__ << " forcing exit" << endl;
  exit(1);
 }
 }
 }

My problem is that typical c++ expressions as cerr, exit string are not recognized. What is the problem?


Solution

  • You need to tell the indexer, where the standard include files can be found.

    Go to your project settings and add the path to the standard include files in the "Paths and Symbols" section as described here.

    Rebuild the index afterwards, or choose yes when asked for.

    Eclipse CDT cannot retrieve that information if you use CMake as build system for your project, instead of an internal builder.