[英]error , Symbol 'vector' could not be resolved
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 我在linux中使用eclipse开发一个c ++应用程序,我从以下代码行得到这个编辑器注释错误“符号'向量'无法解析”
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.
我明确下载了STL,但没有用。 Do I have to re install GCC on my linux ?
我是否必须在我的Linux上重新安装GCC?
在Eclipse中,右键单击项目名称...选择Index ... Rebuild。
I had the same issue. 我遇到过同样的问题。 I believe the problem arises from how std:: autocompletion is updated.
我认为问题源于std :: autocompletion如何更新。 Eclipse should be getting this from the Path and Symbols, but it could be buggy.
Eclipse应该从Path和Symbols中获取它,但它可能是错误的。 I had to clean all Eclipse settings after upgrading gcc (thus, g++), since you're in Linux it's under your home folder ~/.eclipse/.
升级gcc后我必须清理所有Eclipse设置(因此,g ++),因为你在Linux中它位于你的主文件夹〜/ .eclipse /下。
Thus, 从而,
1) Re-started Eclipse after cleaning ~/.eclipse/. 1)清理〜/ .eclipse /后重新启动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/) 2)检查路径和符号(右键单击项目>常规>路径和符号)包括所有已升级的gcc和c ++包含目录(向量应位于./gcc/version/include/c++/version/下)
3) Rebuild index. 3)重建索引。
4) Created a *.cpp file that includes the *.h where the error is showing. 4)创建一个* .cpp文件,其中包含显示错误的* .h。 This will force Eclipse to backtrace dependencies for *.h.
这将迫使Eclipse回溯* .h的依赖关系。
5) Rebuild index and/or restart a few times as required, now I can see vector at the end of std:: autocompletion. 5)根据需要重建索引和/或重启几次,现在我可以在std :: autocompletion结束时看到vector。
(see picture)
(见图)
Hope it helps! 希望能帮助到你!
You need to include the STL vector definition in your program. 您需要在程序中包含STL向量定义。 Put:
放:
#include <vector>
at the top of your file and it should work. 在文件的顶部,它应该工作。
See Also related question: Eclipse CDT: Symbol 'cout' could not be resolved 另请参阅相关问题: Eclipse CDT:无法解析符号'cout'
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>
对我来说,问题是在
#include <vector>
某处有#include <bits/c++config>
,其中包含的路径与#include <vector>
ie: /usr/include/c++/4.6/x86_64-linux-gnu
即:/
/usr/include/c++/4.6/x86_64-linux-gnu
#include<vector>
应该包括在顶部。
#include <vector>
另外,std :: vector是模板类型,所以你必须使用它
std::vector<char> buffer;
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.
我明确下载了STL,但没有用。
Hopefully you mean libstdc++, GNU's implementation of the C++ Standard Library, and you probably shouldn't have done this. 希望你的意思是libstdc ++,GNU的C ++标准库的实现,你可能不应该这样做。 Your toolchain comes with the proper stdlib implementation.
您的工具链附带了正确的stdlib实现。
Do I have to re install GCC on my linux?
我是否必须在我的Linux上重新安装GCC?
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++
而不是 gcc
; g++
automatically links in the C++ runtimes and stdlib implementation, whereas gcc
is designed for C. g++
自动链接C ++运行时和stdlib实现,而gcc
是为C设计的。
Created a *.cpp
file that includes the *.h
where the error is showing. 创建一个
*.cpp
文件,其中包含显示错误的*.h
。 This will force Eclipse to backtrace dependencies for *.h
. 这将迫使Eclipse回溯
*.h
依赖关系。
Is working for me... 为我工作......
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
: 使用Eclipse Neon for Linux我用
Quick Fix
解决了它:
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. 您的设置中很可能缺少一些特定于系统的包含目录,这使得索引器无法正确解析iostream,从而导致错误。 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. 选择
Index -> Search
未解决的项目上下文菜单中的包含将为您提供可在/usr/include
搜索的未解析包含列表,并将包含目录添加到C ++包含项目属性中的路径和符号。
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. 在我的系统上,我必须添加
/usr/include/c++/4.6/x86_64-linux-gnu
来/usr/include/c++/4.6/x86_64-linux-gnu
bits/c++config.h
以及更多目录。
Don't forget to rebuild the index (Index -> Rebuild) after adding include directories. 添加包含目录后,不要忘记重建索引(索引 - >重建)。
Apparently vector belongs to C++ standard template library from MinGW perspective. 显然,vector从MinGW的角度来看属于C ++标准模板库。 so in addition to
所以除了
#include <vector>
Add 加
using namespace std;
after the header file inclusions. 在头文件包含之后。
adding #include< vector > and using namespace std; 添加#include <vector>并使用命名空间std; solved my problem
解决了我的问题
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.