error , Symbol 'vector' could not be resolved

46,204

Solution 1

In Eclipse, right-click on the project name...Select Index...Rebuild.

Solution 2

You need to include the STL vector definition in your program. Put:

#include <vector>

at the top of your file and it should work.

Solution 3

I had the same issue. I believe the problem arises from how std:: autocompletion is updated. Eclipse should be getting this from the Path and Symbols, but it could be buggy. I had to clean all Eclipse settings after upgrading gcc (thus, g++), since you're in Linux it's under your home folder ~/.eclipse/.

Thus,

1) Re-started Eclipse after cleaning ~/.eclipse/.

2) checked that Path and Symbols (under right-click on project > General > Path and Symbols) included all the upgraded gcc and c++ include directories (vector should be under ./gcc/version/include/c++/version/)

3) Rebuild index.

4) Created a *.cpp file that includes the *.h where the error is showing. This will force Eclipse to backtrace dependencies for *.h.

5) Rebuild index and/or restart a few times as required, now I can see vector at the end of std:: autocompletion.

enter image description here(see picture)

Hope it helps!

Solution 4

See Also related question: Eclipse CDT: Symbol 'cout' could not be resolved

for me the problem was that in #include <vector> somewhere there is #include <bits/c++config> which has a different include path than #include <vector>

i.e.: /usr/include/c++/4.6/x86_64-linux-gnu

Solution 5

I feel that some library is missing or the paths are not set.

Yes, this sounds like a linker error. Linkers deal with symbols.

I explicitly downloaded STL but its of no use.

Hopefully you mean libstdc++, GNU's implementation of the C++ Standard Library, and you probably shouldn't have done this. Your toolchain comes with the proper stdlib implementation.

Do I have to re install GCC on my linux?

Probably wise. And let this installation handle the standard library.

Also, on the off-chance that you're playing with your compilation command line, remember to invoke g++ not gcc; g++ automatically links in the C++ runtimes and stdlib implementation, whereas gcc is designed for C.

Share:
46,204
Umair Zaman
Author by

Umair Zaman

Updated on July 09, 2022

Comments

  • Umair Zaman
    Umair Zaman almost 2 years

    I am using eclipse in linux to develop a c++ application and I am getting this editor annotation error "Symbol 'vector' could not be resolved" from the following code lines

    std::vector<unsigned char> buffer;
    

    I feel that some library is missing or the paths are not set. I explicitly downloaded STL but its of no use. Do I have to re install GCC on my linux ?

  • Umair Zaman
    Umair Zaman almost 13 years
    i have included this at the top but of no use
  • StevieG
    StevieG about 12 years
    Err.. if you're going to downvote a post, at least have the decency to explain why...
  • StevieG
    StevieG almost 12 years
    And again.. this post is a year old now.. the answer is perfectly reasonable, and without any further response from the OP, there's not really much I can do to improve it. So if you're going to downvote, I'd love to know why?!?
  • Cookster
    Cookster over 11 years
    FYI - not the same as a refresh (I thought it was).
  • jespestana
    jespestana about 11 years
    I think that this answer is correct. The question is related to this other solved post: stackoverflow.com/questions/10803685/… . I solved the problem with a similar procedure to the one explained by @wgodoy (using the mentioned post).
  • waynix
    waynix almost 6 years
    @StevieG your answer maybe right if there is an compilation error. But op states that he is getting a annotation error. It is an specific problem to eclipse as it uses an different code scanner for the annotation task. I have a similar problem like op and my code is compiling and linking fine but eclipse still messes up the standard template library.