Eclipse CDT: Symbol 'cout' could not be resolved
Solution 1
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.
Solution 2
To get rid of symbol warnings you don't want, first you should understand how Eclipse CDT normally comes up with unknown symbol warnings in the first place. This is its process, more or less:
- Eclipse detects the GCC toolchains available on the system
- Your Eclipse project is configured to use a particular toolchain
- Eclipse does discovery on the toolchain to find its include paths and built-in defines, i.e. by running it with relevant options and reading the output
- Eclipse reads the header files from the include paths
- Eclipse indexes the source code in your project
- Eclipse shows warnings about unresolved symbols in the editor
It might be better in the long run to fix problems with the earlier steps rather than to override their results by manually adding include directories, symbols, etc.
Toolchains
If you have GCC installed, and Eclipse has detected it, it should list that GCC as a toolchain choice that a new C++ project could use, which will also show up in Window -> Preferences -> C/C++ -> New CDT Project Wizard
on the Preferred Toolchains
tab's Toolchains
box on the right side. If it's not showing up, see the CDT FAQ's answer about compilers that need special environments (as well as MinGW and Cygwin answers for the Windows folk.)
If you have an existing Eclipse C++ project, you can change the associated toolchain by opening the project properties, and going to C/C++ Build -> Tool Chain Editor
and choosing the toolchain you want from the Current toolchain:
pulldown. (You'll have to uncheck the Display compatible toolchains only
box first if the toolchain you want is different enough from the one that was previously set in the project.)
If you added a toolchain to the system after launching Eclipse, you will need to restart it for it to detect the toolchain.
Discovery
Then, if the project's C/C++ Build -> Discovery Options -> Discovery profiles scope
is set to Per Language
, during the next build the new toolchain associated with the project will be used for auto-discovery of include paths and symbols, and will be used to update the "built-in" paths and symbols that show up in the project's C/C++ General -> Paths and Symbols
in the Includes
and Symbols
tabs.
Indexing
Sometimes you need to re-index again after setting the toolchain and doing a build to get the old symbol warnings to go away; right-click on the project folder and go to Index -> Rebuild
to do it.
(tested with Eclipse 3.7.2 / CDT 8)
Solution 3
Thanks loads for the answers above. I'm adding an answer for a specific use-case...
On a project with two target architectures each with its own build configuration (the main target is an embedded AVR platform; the second target is my local Linux PC for running unit tests) I found it necessary to set Preferences -> C/C++ -> Indexer -> Use active build configuration
as well as to add /usr/include/c++/4.7
, /usr/include
and /usr/include/c++/4.7/x86_64-linux-gnu
to Project Properties -> C/C++ General -> Paths and Symbols
and then to rebuild the index.
Solution 4
I tried the marked solution here first. It worked but it is kind hacky, and you need to redo it every time you update the gcc. I finally find a better solution by doing the followings:
Project
->Properties
->C/C++ General
->Preprocessor Include Paths, Macros, etc.
Providers
->CDT GCC built-in compiler settings
- Uncheck
Use global provider shared between projects
(you can also modify the global provider if it fits your need) - In
Command to get compiler specs
, add-std=c++11
at the end Index
->Rebuild
Voila, easy and simple. Hopefully this helps.
Note: I am on Kepler. I am not sure if this works on earlier Eclipse.
Solution 5
I had a similar problem with *std::shared_ptr* with Eclipse using MinGW and gcc 4.8.1. No matter what, Eclipse would not resolve *shared_ptr*. To fix this, I manually added the __cplusplus macro to the C++ symbols and - viola! - Eclipse can find it. Since I specified -std=c++11 as a compile option, I (ahem) assumed that the Eclipse code analyzer would use that option as well. So, to fix this:
- Project Context -> C/C++ General -> Paths and Symbols -> Symbols Tab
- Select C++ in the Languages panel.
- Add symbol __cplusplus with a value of 201103.
The only problem with this is that gcc will complain that the symbol is already defined(!) but the compile will complete as before.
Jeff
Updated on August 20, 2020Comments
-
Jeff over 3 years
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
andusing namespace std;
cout
but it still says unresolved.I have imported
iostream
andcstdlib
.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).
-
tony gil over 11 yearsperfect solution, kudos. solved my problem with local error messages regarding mysql methods and classes in c++ on adt+eclipse juno bundle with cdt added (ubuntu 12.04). upvote, of course!
-
wall-e about 11 yearsfor me, Ubuntu 10.04, have to add /usr/include/c++/4.4/i486-linux-gnu
-
jespestana about 11 yearsI had to add include_directories("/usr/include/x86_64-linux-gnu") to my cmake file, then the generated eclipse project is able to parse vector, cout, string, and all the other present components from the C++ STL library. For those who need more information about configuring Eclipse CDT projects from CMake files see this post: stackoverflow.com/questions/9453851/…
-
hAcKnRoCk almost 11 yearsThe question was how to resolve the includes. Not how to delete eclipse warnings.
-
resigned over 10 yearsNevertheless this seems to fix the indexer sometimes - at least it worked for me.
-
Mark over 9 yearsI just had to rebuild the index, after upgrading my system; the newer eclipse 4.4.1 had had some difficulty while importing workspace / updating plugins etcetera
-
HighCommander4 over 7 yearsThis is the solution to a different problem, that of C++11 symbols not being resolved. The OP was having trouble getting even C++98 symbols like
std::cout
resolved. -
Sandeep over 2 yearsFor me the following worked: 1). [Select Project Name] --> Index --> Search for Unresolved Includes 2). Clean Project 3). Build Project