如何从 Eclipse 索引(静态代码分析)中排除文件?

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

How to exclude files from Eclipse indexing (Static Code Analysis)?

eclipseeclipse-cdtstatic-analysisindexerds-5

提问by ysap

I have a makefile project comprised of many source, header and other files, which I am trying to convert to an Eclipse "native" project. The problem that the Indexer reports errors and warning on files that exist in the directories but are excluded form the build. As a consequence, large parts of my directory tree are marked with the red xsign.

我有一个由许多源文件、头文件和其他文件组成的 makefile 项目,我正在尝试将其转换为 Eclipse“本机”项目。Indexer 报告目录中存在但从构建中排除的文件的错误和警告的问题。因此,我的目录树的大部分都标有红色x符号。

How can I make the Indexer to ignore specific file and/or directories?

如何让索引器忽略特定文件和/或目录?

Note: when defining a directory as "Derived" it is excluded form further searches, but unfortunately not from code analysis. Using project Resource Filters does not solve the problem either.

注意:当将目录定义为“派生”时,它会被排除在进一步搜索之外,但不幸的是不会被代码分析排除在外。使用项目资源过滤器也不能解决问题。

回答by Lonzak

Individual files are tricky however folders should be possible. Right click on the project -> Properties -> C/C++ General -> Paths and Symbols

单个文件很棘手,但文件夹应该是可能的。 Right click on the project -> Properties -> C/C++ General -> Paths and Symbols

Have a look at the 'Source Location' tab:

查看“源位置”选项卡:

(a)completely remove a source folder or

(a)完全删除源文件夹或

(b)define an exlusion filter (where you can also add folders, filters and to a certain extent also files etc.)

(b)定义排除过滤器(您还可以在其中添加文件夹、过滤器以及在一定程度上添加文件等)

(c)Highlight one or several files or folders by left clicking it. Then, right click one of the selected files, then chose Resource Configurations -> Exclude from build.... It will exclude all selected files or folders.

(c)通过左键单击突出显示一个或多个文件或文件夹。然后,右键单击所选文件之一,然后选择Resource Configurations -> Exclude from build.... 它将排除所有选定的文件或文件夹。

(d)Also take a look at File Types(in C/C++ General) and click through the other tabs of 'Paths and Symbols' and see if something can be removed...

(d)还看一下File Types(在 C/C++ General 中)并单击“路径和符号”的其他选项卡,看看是否可以删除某些内容...

(e)And as you may have seen there is also an Indexer (Right click on the project -> Properties -> Indexerwhich can be configured

(e)正如您可能已经看到的,还有一个索引器(Right click on the project -> Properties -> Indexer可以配置

Now I hope the DS-5 guys didn't deactivate all of those options...

现在我希望 DS-5 的人没有停用所有这些选项......

Update:Of course those options are also available (at least some of those) in CDT. I changed my description accordingly...

更新:当然,这些选项在 CDT 中也可用(至少是其中一些)。我相应地更改了我的描述...

回答by ysap

Note - this is a partial answer

注意 - 这是部分答案

Like many features in Eclipse, this is yet another option buried inside the endless configuration dialogs, and has a default setting which is contrasting the common sense...

与 Eclipse 中的许多功能一样,这是隐藏在无尽配置对话框中的另一个选项,并且具有与常识形成对比的默认设置......

In order to exclude indexing of files that are excluded from the build, uncheck:

为了排除从构建中排除的文件的索引,取消选中:

Window-> Preferences-> C/C++-> Indexer-> Index source files not included in the build

Window-> Preferences-> C/C++-> Indexer->Index source files not included in the build

I did not find yet a way of excluding files the areincluded in the build. Similarly, I could not find how to exclude whole directories, but if all sources in a directory are excluded from build, then with this setting unchecked, it will be excluded from indexing as well.

我还没有找到排除构建包含的文件的方法。同样,我找不到如何排除整个目录,但是如果目录中的所有源都从构建中排除,那么在未选中此设置的情况下,它也将从索引中排除。