即使构建成功,Eclipse c++ 类型也无法解析错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10041453/
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
Eclipse c++ Type could not be resolved error even though build is successful
提问by Juozas Kontvainis
I have mixed C++ / Java project in Eclipse. I've setup a build.mk file and Eclipse builds project successfully when all files in editor are closed. When I open a .h or a .cpp file Eclipse finds a lot of undefined symbols in them. I have references to 3rd party API and all the problems seem to be related to symbols from that API. Strangely, some types are considered defined in Eclipse, and some are considered undefined even though in some cases they are defined in the same .h file.
我在 Eclipse 中混合了 C++/Java 项目。我已经设置了一个 build.mk 文件,当编辑器中的所有文件都关闭时,Eclipse 成功构建了项目。当我打开 .h 或 .cpp 文件时,Eclipse 会在其中发现很多未定义的符号。我参考了 3rd 方 API,所有问题似乎都与来自该 API 的符号有关。奇怪的是,有些类型被认为是在 Eclipse 中定义的,有些类型被认为是未定义的,即使在某些情况下它们是在同一个 .h 文件中定义的。
My colleague is not experiencing any of these problems, but we are clueless where to start solving this problem. We already made sure that our Eclipse include directories are the same. Is there some way to compare eclipse project settings?
我的同事没有遇到任何这些问题,但我们不知道从哪里开始解决这个问题。我们已经确保我们的 Eclipse 包含目录是相同的。有什么方法可以比较eclipse项目设置吗?
Update: .cproject files and .project files and files in .settings directory know differ only by some paths. Did not help to solve my problem though.
更新:.cproject 文件和 .project 文件以及 .settings 目录中的文件仅在某些路径上有所不同。虽然没有帮助解决我的问题。
回答by harper
I had the same problem. It could be resolved by flushing the Eclipse indexer.
我有同样的问题。它可以通过刷新 Eclipse 索引器来解决。
I used the projects context menu and selected Index->Rebuild
and Index->Freshen All Files
. The last removed the error messages.
我使用了项目上下文菜单并选择了Index->Rebuild
和Index->Freshen All Files
。最后删除了错误消息。
回答by Juozas Kontvainis
Turns out I needed to change Code Analysis settings that are on Launching tab, and I simply did not see that tab.
结果我需要更改启动选项卡上的代码分析设置,而我根本没有看到该选项卡。
回答by Leon Rom
I had the same problem. It take place when in included file I'd used
我有同样的问题。它发生在我使用的包含文件中
namespace std
命名空间标准
without using it in main file or vice versa. Do check using namespaceequally.
不在主文件中使用它,反之亦然。做同样检查使用命名空间。
回答by Link1600
I finally figured this out. Flushing the Eclipse Indexer as mentioned in the top voted answer didn't work for me. This is what I had to do:
我终于想通了这一点。在最高投票的答案中提到的刷新 Eclipse 索引器对我不起作用。这就是我必须做的:
I went to: Project -> Properties -> C/C++ General -> Paths and Symbols -> Includes
我去了:项目 -> 属性 -> C/C++ 常规 -> 路径和符号 -> 包含
Here I had the path for my include directory, but what I had to do was delete the directory path, and then re-add it making sure to check the box "Add to all configurations". I also checked the box "Add to all languages", but I don't think that is necessary.
在这里,我有包含目录的路径,但我必须删除目录路径,然后重新添加它,确保选中“添加到所有配置”框。我还选中了“添加到所有语言”框,但我认为没有必要。
After this, you may need to then click on Project -> C/C++ Index -> Rebuild. I didn't need to, but you might. Also, obviously instead of C/C++ in the paths above, it will be Java or whatever language you are dealing with.
之后,您可能需要单击 Project -> C/C++ Index -> Rebuild。我不需要,但你可能会。此外,很明显,上面路径中的 C/C++ 不是 C/C++,而是 Java 或您正在处理的任何语言。
回答by Deepak
You can compile and run the source code also by Right Click On Project>Run C/C++ Code Analysis. This will solve your problem.
您也可以通过右键单击项目>运行 C/C++ 代码分析来编译和运行源代码。这将解决您的问题。