Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"string could not resolved" error in Eclipse for C++ (Eclipse can't resolve standard library)

Tags:

c++

eclipse

I have the following code in eclipse for c++ and it's underlining string and cout and saying could not be resolved.

#include <string>
#include <iostream>

using namespace std;


int main()
{
    string s;
    s = "hello world";
    cout << s;
    return 0;

}

Anyone know why?

edit: screenshot

Edit: I have found a solution thanks everyone (see answers).

enter image description here

like image 314
code511788465541441 Avatar asked Oct 26 '11 15:10

code511788465541441


3 Answers

I've also had this issue.

I've found out that it is because Eclipse couldn't find all include headers.

Easy fix:

This simple and quick solution might fix your problem (for example, when the Eclipse project was moved to a different location on disk, then imported again in Eclipse), if not, jump to the next section (Detailed fix).

  1. Go to project > properties > C/C++ Build > Tool Chain Editor
  2. Change the Current toolchain to any other value, click Apply
  3. Set the Current toolchain to the original value, click Apply
  4. Compile your project

Detailed fix:

Before proceeding check if your toolchain is properly installed.

  1. Switch to a new workspace.
  2. Remove .cproject file and the ".settings" folder
  3. Import your project as Makefile project (or just create a new if you prefer CDT Build system)
  4. Go to project-> properties->C/C++ Build->Toolchain editor. Choose your toolchain.
  5. Press project->Index->Rebuild
  6. If the problem isn't resolved, change system language to English and try the above steps again.

Outdated answer:

This answer has been outdated. Proceed if nothing of the above helps

If the previous steps don't help we'll need to setup include directories manually (not recommended though)

  1. Search all unresolved headers using "Right click on Project > Index > Search for unresolved includes".
  2. Search their locations using "find /usr/include/ -name vector -print"
  3. Put include folder paths to "Right click on Project > Properties > C++ General/Path and Symbols/C++"
  4. Run "Right click on Project > Index > Rebuild"
  5. Start from step 1 if there are any unresolved symbols left.
like image 105
14 revs, 3 users 79% Avatar answered Nov 12 '22 08:11

14 revs, 3 users 79%


The problem was that I needed to have both minGW and MSYS installed and added to PATH.

The problem is now fixed.

like image 45
code511788465541441 Avatar answered Nov 12 '22 08:11

code511788465541441


I've just replied to the related question given by Vanuan (Eclipse CDT: Unresolved inclusion of stl header), and this is my answer :

You could also try use "CDT GCC Built-in Compiler Settings". Go to the project properties > C/C++ General > Preprocessor Include Path > Providers tab then check "CDT GCC Built-in Compiler Settings" if it is not.

None of the other solutions (play with include path, etc) worked for me for the type 'string', but this one fixed it.

like image 6
Virtual Avatar answered Nov 12 '22 06:11

Virtual