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
In Eclipse, right-click on the project name...Select Index...Rebuild.
adding #include< vector > and using namespace std; solved my problem
You need to include the STL vector definition in your program. Put:
#include <vector>
at the top of your file and it should work.
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.
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.
(see picture)
Hope it helps!
#include <vector>
Also, std::vector is template type, so you have to use it like
std::vector<char> buffer;