Linux 错误,符号“向量”无法解析

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6980186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-05 05:33:52  来源:igfitidea点击:

error , Symbol 'vector' could not be resolved

c++linuxeclipse

提问by Umair Zaman

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. Do I have to re install GCC on my linux ?

我觉得缺少某些库或未设置路径。我明确下载了 STL 但它没有用。我必须在我的 linux 上重新安装 GCC 吗?

回答by StevieG

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

您需要在程序中包含 STL 向量定义。放:

#include <vector>

at the top of your file and it should work.

在文件的顶部,它应该可以工作。

回答by iammilind

#include<vector>

should be included at top.

应该包括在顶部。

回答by J0HN

#include <vector>

Also, std::vector is template type, so you have to use it like

另外, std::vector 是模板类型,所以你必须像这样使用它

std::vector<char> buffer;

回答by Lightness Races in Orbit

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. Your toolchain comes with the proper stdlib implementation.

希望您指的是 libstdc++,GNU 对 C++ 标准库的实现,您可能不应该这样做。您的工具链带有正确的 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++notgcc; g++automatically links in the C++ runtimes and stdlib implementation, whereas gccis designed for C.

此外,如果您正在使用编译命令行,请记住调用g++notgcc; g++在 C++ 运行时和 stdlib 实现中自动链接,而gcc专为 C 设计。

回答by RDH

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

在 Eclipse 中,右键单击项目名称...选择 Index...Rebuild。

回答by wgodoy

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/.

我遇到过同样的问题。我相信问题出在 std:: 自动完成的更新方式上。Eclipse 应该从 Path 和 Symbols 中得到这个,但它可能有问题。升级 gcc(因此,g++)后,我必须清除所有 Eclipse 设置,因为您使用的是 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. This will force Eclipse to backtrace dependencies for *.h.

4) 创建了一个 *.cpp 文件,其中包含显示错误的 *.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:: 自动完成的末尾看到向量。

enter image description here(see picture)

在此处输入图片说明(见图)

Hope it helps!

希望能帮助到你!

回答by guangge

Created a *.cppfile that includes the *.hwhere the error is showing. This will force Eclipse to backtrace dependencies for *.h.
Is working for me...

创建了一个*.cpp包含*.h错误显示位置的文件。这将强制 Eclipse 回溯*.h.
正在为我工​​作...

回答by Alex

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>

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

IE: /usr/include/c++/4.6/x86_64-linux-gnu

回答by Ahmed_Faraz

adding #include< vector >and using namespace std;solved my problem

添加#include<vector>使用命名空间 std;解决了我的问题

回答by Ahmed_Faraz

I know that this problem was already solved, but it still appears as the top result on Google.

我知道这个问题已经解决了,但它仍然出现在谷歌上的最高结果。

Using Eclipse Neonfor LinuxI solved it with Quick Fix:

使用Eclipse Neonfor Linux我解决了它Quick Fix

  • right click at "vector" in the editor,
  • then "Quick Fix"
  • 右键单击编辑器中的“矢量”,
  • 然后“快速修复”