可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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 ?
回答1:
In Eclipse, right-click on the project name...Select Index...Rebuild.
回答2:
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!
回答3:
You need to include the STL vector definition in your program. Put:
#include <vector>
at the top of your file and it should work.
回答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
回答5:
#include<vector>
should be included at top.
回答6:
#include <vector>
Also, std::vector is template type, so you have to use it like
std::vector<char> buffer;
回答7:
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.
回答8:
Created a *.cpp
file that includes the *.h
where the error is showing. This will force Eclipse to backtrace dependencies for *.h
.
Is working for me...
回答9:
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.
回答10:
Apparently vector belongs to C++ standard template library from MinGW perspective. so in addition to
#include <vector>
Add
using namespace std;
after the header file inclusions.
回答11:
I know that this problem was already solved, but it still appears as the top result on Google.
Using Eclipse Neon for Linux I solved it with Quick Fix
:
- right click at "vector" in the editor,
- then "Quick Fix"
回答12:
adding #include< vector > and using namespace std; solved my problem