Eclipse CDT: Symbol 'cout' could not be resolved

Jeff picture Jeff · May 29, 2012 · Viewed 190.9k times · Source

The error is as above. I have what should be all the necessary files include in the eclipse project:

/usr/include/c++/4.6
/usr/include
/usr/include/linux
/usr/local/include

etc.

I tried std::cout and using namespace std; cout but it still says unresolved.

I have imported iostream and cstdlib.

Also, I'm on Ubuntu 12.04 with eclipse 3.7.2.

Code snippet:

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include "XPLMDisplay.h"
#include "XPLMGraphics.h"

int XPluginStart(char * outName,  char * outSig,  char * outDesc) {
    /* ... */
    std::cout << "test" << std::endl;
    /* ... */
}

using namespace std;


UPDATE: I had created the eclipse project from existing code. Creating a new c++ project fixes it. I'll accept an answer that explains what setting in the existing project could cause this (so I don't have to cut & paste all my projects).

Answer

vitaut picture vitaut · May 29, 2012

Most likely you have some system-specific include directories missing in your settings which makes it impossible for indexer to correctly parse iostream, thus the errors. Selecting Index -> Search For Unresolved Includes in the context menu of the project will give you the list of unresolved includes which you can search in /usr/include and add containing directories to C++ Include Paths and Symbols in Project Properties.

On my system I had to add /usr/include/c++/4.6/x86_64-linux-gnu for bits/c++config.h to be resolved and a few more directories.

Don't forget to rebuild the index (Index -> Rebuild) after adding include directories.