带有 CDT 的 Eclipse 3.7.0 Indigo 显示许多错误的编译错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7962655/
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-09-19 17:16:08  来源:igfitidea点击:

Eclipse 3.7.0 Indigo with CDT shows many false compilation errors

c++eclipseeclipse-cdt

提问by zonyitoo

I have updated my Ubuntu box to 11.10 and then Eclipse also have been updated to 3.7.0 Indigo with CDT 8.0.1

我已经将我的 Ubuntu 盒子更新到 11.10,然后 Eclipse 也更新到了 3.7.0 Indigo 和 CDT 8.0.1

Then the following problem occurs:

然后出现以下问题:

Eclipse errors

Eclipse 错误

I have included the vector header file but the compiler said that Symbol 'vector' could not be resolved. I also defined #define int Comparable, but Eclipse also said Symbol 'Comparable' could not be resolvedand so on....

我已经包含了向量头文件,但编译器说Symbol 'vector' could not be resolved. 我也定义了#define int Comparable,但是Eclipse也说了Symbol 'Comparable' could not be resolved等等....

Although lots of errors occur, compiling was finished successfully!

虽然出现了很多错误,但编译成功!

I have tried to use g++ to compile the code, it had no problem.

我试过用g++编译代码,没问题。

采纳答案by Matteo

Time after time a crash of Eclipse, the VM or the computer or even just long months of development start to wear down the stability of the workspace where Eclipse stores everything.

一次又一次的 Eclipse、VM 或计算机崩溃,甚至只是长达数月的开发,都开始削弱 Eclipse 存储所有内容的工作区的稳定性。

Check the <workspace dir>\.metadatadirectory to get an idea of just how much Eclipse generates and stores in your workspace. Every time you add a plugin, upgrade a plugin, remove a plugin that puts and changes information in your workspace.

检查<workspace dir>\.metadata目录以了解 Eclipse 在您的工作区中生成和存储了多少。每次添加插件时,升级插件,删除在工作区中放置和更改信息的插件。

A proof is that this issue usually comes just after upgrading Eclipse. (In my case to Indigo).

一个证据是这个问题通常在升级 Eclipse 之后出现。(就我而言,Indigo)。

The easiest way to fix up a dusty workspace is using the -cleancommand line argument to the eclipse.exe executable.

修复尘土飞扬的工作区的最简单方法是使用-cleaneclipse.exe 可执行文件的命令行参数。

Eclipse help docs tell us what this command does:

Eclipse 帮助文档告诉我们这个命令的作用:

if set to "true", any cached data used by the OSGi framework and eclipse runtime will be wiped clean. This will clean the caches used to store bundle dependency resolution and eclipse extension registry data. Using this option will force eclipse to reinitialize these caches.

如果设置为“true”,则 OSGi 框架和 eclipse 运行时使用的任何缓存数据都将被清除。这将清理用于存储包依赖解析和 Eclipse 扩展注册表数据的缓存。使用此选项将强制 eclipse 重新初始化这些缓存。

There are three ways one can use the -cleancommand line argument:

可以通过三种方式使用-clean命令行参数:

  1. Edit the eclipse.ini file located in your and add it as the first argument on the first line.
  2. Edit the shortcut you use to start Eclipse and add it as the first argument.
  3. Create a batch or shell script that calls the Eclipse executable with the -cleanargument.
  1. 编辑位于您的 eclipse.ini 文件并将其添加为第一行的第一个参数。
  2. 编辑用于启动 Eclipse 的快捷方式并将其添加为第一个参数。
  3. 创建一个批处理或 shell 脚本,用-clean参数调用 Eclipse 可执行文件。

The advantage of step 3 is you can keep the script around and use it each time you want to clean out the workspace.

第 3 步的优点是您可以保留脚本并在每次要清理工作区时使用它。

This pagesolved the problem to me!Hope it can help everybody else.

这个页面解决了我的问题!希望它可以帮助其他人。

回答by Catskul

The problem is that there are a bunch of include directories that are missing from the indexer's perspective.

问题是从索引器的角度来看,有一堆包含目录缺失。

Adding the following worked for me, but may depend on your particular setup where they actually exist:

添加以下内容对我有用,但可能取决于您实际存在的特定设置:

/usr/include/c++/4.6.1
/usr/include/                
/usr/include/c++             
/usr/include/c++/4.6         
/usr/include/x86_64-linux-gnu
/usr/include/asm-generic
/usr/include/c++/4.6.1/x86_64-linux-gnu/

They can be set in Project>Properties>C++ Include Paths

它们可以设置在 Project>Properties>C++ Include Paths

Presumably, in the future, the platform specializations for the CDT will included these automatically. I recall reading that somewhere, but cannot provide a reference.

据推测,将来,CDT 的平台专业化将自动包含这些。我记得在某处读过,但无法提供参考。

回答by Chuong

In the project properties, go to C/C++ Build > Tool Chain Editor, tick Display compatible toolchains only, and select Linux GCC and click Apply button.

在项目属性中,转到 C/C++ Build > Tool Chain Editor,勾选 Display compatible toolchains only,然后选择 Linux GCC 并单击 Apply 按钮。

Now if you go to C\C++ General > Paths and Symbols, you will see new list of include paths added. If you rebuild index, the error messages should go away.

现在,如果您转到 C\C++ General > Paths and Symbols,您将看到添加的包含路径的新列表。如果您重建索引,错误消息应该会消失。

回答by user1546658

Updated index option to active build configuration works for me,

更新了活动构建配置的索引选项对我有用,

also I removed some files from the file list of being indexed up-front,

我还从预先编制索引的文件列表中删除了一些文件,

回答by Erzsébet Geréb

When you create a C++ project (in my case from existing code) you have to set the 'Toolchain for Indexer Settings' to the compiler you use ('GNU Autotools Toolchains' in my case). After this 'Path and Symbols' will show the correct path to the include files of your compiler. The bugs will disappear. This setting was useful only during creating the project, setting it later did not help.

当您创建 C++ 项目时(在我的情况下是从现有代码中创建的),您必须将“用于索引器设置的工具链”设置为您使用的编译器(在我的情况下是“GNU Autotools 工具链”)。在此之后,“路径和符号”将显示编译器包含文件的正确路径。错误将消失。此设置仅在创建项目期间有用,稍后设置它没有帮助。

In indigo 3.7.2 version (and up may be) your changes can be effect after reindexing. Eclipse ask for "reindexing". Lower versions can require a manual reindexing header tags etc.

在 indigo 3.7.2 版本(可能更高版本)中,您的更改可以在重新索引后生效。Eclipse 要求“重新索引”。较低版本可能需要手动重新索引标题标签等。

回答by Gyan aka Gary Buyn

The code analysis is causing this. It's not actually compiling the code but just doing some static checks for quick feedback. Unfortunately I don't know how to fix it, I just disabled it. Sorry I'm at work so I don't have CDT in front of me but I think it's something like:

代码分析导致了这种情况。它实际上并不是在编译代码,而只是进行一些静态检查以获得快速反馈。不幸的是我不知道如何修复它,我只是禁用了它。对不起,我在工作,所以我面前没有 CDT,但我认为它是这样的:

Window > Preferences > C++ General > Code Analysis

Go there and un-check all the boxes to disable it.

去那里取消选中所有框以禁用它。

回答by Dan

I am answering here because this is the closest question to my problem.

我在这里回答是因为这是最接近我的问题的问题。

I used QT Eclipse integration with Helios (3.6.2) with no major problems. I was using mingw 4.6.2, which I had installed to c:\mingw. I wanted to upgrade to Indigo, which fixed some minor issues I was having with CDT.

我使用了 QT Eclipse 与 Helios (3.6.2) 的集成,没有出现大问题。我使用的是 mingw 4.6.2,我已将其安装到 c:\mingw。我想升级到 Indigo,它解决了我在使用 CDT 时遇到的一些小问题。

However, under Indigo (3.7 SR2) Eclipse began underlining trivial functions, as being unresolved, such as:

但是,在 Indigo (3.7 SR2) 下,Eclipse 开始强调琐碎的功能,因为未解决,例如:

function 'fprintf' could not be resolved
function 'memset' could not be resolved

even though #include was not underlined, could be opened, and included fprintf in the header. And even though the code itself compiled fine.

即使 #include 没有下划线,也可以打开,并且在标题中包含 fprintf。即使代码本身编译得很好。

If I went back to Helios, the problems went away.

如果我回到 Helios,问题就会迎刃而解。

I tried reindexing, to no avail. I checked my include paths, and they were:

我尝试重新索引,但无济于事。我检查了我的包含路径,它们是:

c:\mingw\include
C:\MinGW\lib\gcc\mingw32.6.2\include

At first, I had just included the first, but not the second. But then I searched for "unresolved includes", and stdio.h was including stdarg.h, which wasn't in the main include folder of mingw, so I added the second. But still, printf was not resolved, and there were no more "unresolved includes".

起初,我只包括了第一个,但没有包括第二个。但是后来我搜索了“未解析的包含”,并且 stdio.h 包含 stdarg.h,它不在 mingw 的主要包含文件夹中,所以我添加了第二个。但是, printf 仍然没有解决,并且没有更多的“未解决的包含”。

I created a new C++ project with one class. I added stdio.h, the paths above, and a call to fprintf. It was underlined! Even though other things from stdio were not underlined.

我用一个类创建了一个新的 C++ 项目。我添加了 stdio.h、上面的路径和对 fprintf 的调用。有下划线!即使 stdio 中的其他内容没有下划线。

Now I knew that it wasn't just a Qt problem.

现在我知道这不仅仅是 Qt 问题。

I worked around on this for a while before I read the bottom post here suggesting removing the include paths and compiling. I didn't believe it would work but gave it a shot. Amazingly, even though the compile failed, the error went away!

在我阅读这里的底部帖子之前,我解决了一段时间,建议删除包含路径并进行编译。我不相信它会起作用,但试了一下。令人惊讶的是,即使编译失败,错误也消失了!

It was then that I took another look at the include paths. They had been updated by the compile step to the following:

就在那时,我又看了一遍包含路径。它们已通过编译步骤更新为以下内容:

c:/mingw/lib/gcc/mingw32/4.6.2/include-fixed
c:/mingw/include
c:/mingw/lib/gcc/mingw32/4.6.2/include
c:/mingw/lib/gcc/mingw32/4.6.2/include/c++/backward
c:/mingw/lib/gcc/mingw32/4.6.2/include/c++/mingw32
c:/mingw/lib/gcc/mingw32/4.6.2/include/c++

These were marked as "built-in" values which I assume means they weren't added by me and could get updated the next time I run a build.

这些被标记为“内置”值,我认为这意味着它们不是我添加的,并且可以在我下次运行构建时更新。

So, I guess the lesson is, including every single include path under mingw, even if Eclipse doesn't find it to be an unresolved include.

所以,我想教训是,包括 mingw 下的每一个包含路径,即使 Eclipse 没有发现它是一个未解析的包含。

The next step was to put all these paths into my Qt project. Unfortunately, after doing so, the unresolved functions were still there. It appears to be some sort of bug with the Qt C/C++ include paths which are different from the CDT C/C++ include paths.

下一步是将所有这些路径放入我的 Qt 项目中。不幸的是,这样做之后,未解决的功能仍然存在。它似乎是 Qt C/C++ 包含路径的某种错误,与 CDT C/C++ 包含路径不同。

回答by iueae

Ok here is what worked for me:

好的,这对我有用:

  • deleted the path to the header files I created from the include path

  • compiled the project (obviously the compiler complains since it is missing user-defined headers)

  • reinserted the path to the header files I created

  • compiled the project again - worked perfectly

  • 从包含路径中删除了我创建的头文件的路径

  • 编译项目(显然编译器抱怨,因为它缺少用户定义的头文件)

  • 重新插入我创建的头文件的路径

  • 再次编译项目 - 完美运行

I can't explain the case :(

我无法解释这种情况:(