如何让 Eclipse 为包含多个“制作项目”的整个 C/C++ 源代码树建立索引?

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

How can I get Eclipse to index an entire C/C++ source tree that contains multiple "make projects"?

eclipseeclipse-cdt

提问by Gordon

I'm having trouble getting Eclipse to index my source code. I'm using Eclipse Helios on Windows XP at the moment.

我在让 Eclipse 索引我的源代码时遇到问题。我目前在 Windows XP 上使用 Eclipse Helios。

I have a directory called src. Within it, I have a bunch of dirs, something like this:

我有一个名为 src 的目录。在其中,我有一堆目录,如下所示:

 src
   -include (common headers)
   -lib
     -libIO (source code for this library)
     -libGUI  (source code for this library)
   -pgms
     -pgm1  (source code and headers for this pgm)
     -pgm2  (source code and headers for this pgm)

Each leaf has its own Makefile. There is no top-level Makefile in src. pgm1 can and does include files from include and lib/libIO and lib/libGUI.

每个叶子都有自己的 Makefile。src 中没有顶层 Makefile。pgm1 可以并且确实包含来自 include 和 lib/libIO 和 lib/libGUI 的文件。

Basically, I want Eclipse to index my entire src directory, without having to set up a C/C++ project for every leaf in my tree.I can't seem to find a way to make this happen.

基本上,我希望 Eclipse 为我的整个 src 目录建立索引,而不必为我的树中的每个叶子设置一个 C/C++ 项目。我似乎无法找到一种方法来实现这一点。

Here's my symptoms; what I'm trying to solve for:

这是我的症状;我试图解决的问题:

When editing source in the pgm1 dir, it references functions that are declared in my include dir header files and defined in source files found in lib/libIO.

在 pgm1 目录中编辑源代码时,它引用在我的包含目录头文件中声明并在 lib/libIO 中的源文件中定义的函数。

However, when I press F3 to get to the declaration of a function, Eclipse says "Could not find symbol 'X' in index". I can't seem to get Eclipse to find either the header declaration or the source definition for the method under my cursor (like the Java module does perfectly). Is this possible?

但是,当我按 F3 进入函数声明时,Eclipse 显示“在索引中找不到符号‘X’”。我似乎无法让 Eclipse 找到光标下方法的头声明或源定义(就像 Java 模块做得很好)。这可能吗?

采纳答案by Gordon

I managed to solve this thanks to comments here.... I ended up recreating my project. I used the Import method to download a project from CVS, and told it to use the New Project wizard to do so. When I got the New Project dialog, I told it this was a C++ Project, and the indexing now works fine.

由于这里的评论,我设法解决了这个问题......我最终重新创建了我的项目。我使用Import 方法从CVS 下载一个项目,并告诉它使用New Project 向导来执行此操作。当我得到 New Project 对话框时,我告诉它这是一个 C++ 项目,现在索引工作正常。

I still wish I could index files without having to attach a specific project type to it, but at least I found an answer.

我仍然希望我可以索引文件而不必附加特定的项目类型,但至少我找到了答案。

Thanks for the help all.

感谢大家的帮助。

回答by MHD

I had exactly same issue as OP but for some reason the menus in Eclipse I was using (Helios Service Release 2) were not "Go to Properties -> C/C++ General -> Paths and Symbols -> Source Location.".

我遇到了与 OP 完全相同的问题,但由于某种原因,我使用的 Eclipse 中的菜单(Helios Service Release 2)不是“转到属性 -> C/C++ 常规 -> 路径和符号 -> 源位置。”。

The way I fixed the issue was :

我解决问题的方式是:

  • in C/C++ view, right-click on top project name;
  • in the menu, select New->C++ Project;
  • in the window that appears, select Convert to and then select C++ project;
  • click OK to close the window.
  • 在 C/C++ 视图中,右键单击顶部的项目名称;
  • 在菜单中,选择New->C++ Project;
  • 在出现的窗口中,选择Convert to,然后选择C++ project;
  • 单击确定关闭窗口。

Eclipse will start indexing right away. Depending on the size of source tree it may take a while but you will have the indexing working finally after that.

Eclipse 将立即开始索引。根据源树的大小,这可能需要一段时间,但之后您将最终进行索引工作。

回答by Somabho

I faced similar situation. I solved it in this way: right-click the project in project View-->select Index-->rebuild.

我遇到了类似的情况。我是这样解决的:在project中右键项目View-->select Index-->rebuild.

回答by CppChase

Exit Eclipse. In workspace go to ".metadata/.plugins/org.eclipse.cdt.core" and delete everything in there.

退出日食。在工作区中,转到“.metadata/.plugins/org.eclipse.cdt.core”并删除其中的所有内容。

回答by user3727512

in the project explorer panel, right click the project you want to re-index, then select index, then select the action you want

在项目资源管理器面板中,右键单击要重新索引的项目,然后选择索引,然后选择所需的操作

回答by Binay Kumar Pradhan

Indexing of files and variables under different flags is always complicated when we have a huge project, lot of files and more importantly lot of different build options. I prefer playing around with the Indexer option to help me browse the entire code. You can find it : Project Properties>C/C++ General/Indexer.

当我们有一个庞大的项目、很多文件,更重要的是有很多不同的构建选项时,不同标志下的文件和变量的索引总是很复杂。我更喜欢使用 Indexer 选项来帮助我浏览整个代码。您可以找到它:项目属性>C/C++ 通用/索引器。

You can choose "Enable project specific settings"

您可以选择“启用项目特定设置”

Then it's up to you to choose the options you want for your project. For a particular build we can choose "Use active build configuration" so that only the files and MACROS are considered which are used by the build script. Or Index all source files in the entire project.

然后由您来为您的项目选择所需的选项。对于特定构建,我们可以选择“使用活动构建配置”,以便仅考虑构建脚本使用的文件和宏。或者索引整个项目中的所有源文件。

回答by basslo

I am using Eclipse Neon 3, here's the solution that worked for me :

我正在使用 Eclipse Neon 3,这是对我有用的解决方案:

  • go to File
  • New
  • Convert to C/C++ Autotools project then select your project and finish.
  • 转到文件
  • 新的
  • 转换为 C/C++ Autotools 项目,然后选择您的项目并完成。

It can take some time to finish indexing, it depends on your project size.

完成索引可能需要一些时间,这取决于您的项目大小。

回答by Andreas Lindell

I have experienced problems with the indexer of Eclipse Luna when there was an unresolved friend declaration in the class declaration - it seems then that the indexer skipped indexing the rest of that class, and all references to it was shown as unresolved by the indexer.

当类声明中存在未解析的朋友声明时,我遇到了 Eclipse Luna 索引器的问题 - 似乎索引器跳过了对该类的其余部分的索引,并且对它的所有引用都显示为索引器未解析。

Solution: removed the unresolved friend declaration (in my case, it was legacy code that was no longer needed).

解决方案:删除未解析的朋友声明(在我的情况下,它是不再需要的遗留代码)。

回答by yep

The following has worked for me in Eclipse Neon: New Project -> C/C++ -> Makefile project with existing code -> Next. Then Navigate to the code and finish the project creation. Indexing starts automatically.

以下在 Eclipse Neon 中对我有用:New Project -> C/C++ -> Makefile project with existing code -> Next。然后导航到代码并完成项目创建。索引自动启动。

回答by Amir Pauker

I am using

我在用

Eclipse IDE for C/C++ Linux Developers

面向 C/C++ Linux 开发人员的 Eclipse IDE

Version: Helios Service Release 2 Build id: 20110218-0911

版本:Helios Service Release 2 版本号:20110218-0911

I followed the suggestions above and in addition I had to mark all referenced projects (with in the work space) using project properties->Project references

我遵循了上面的建议,此外我必须使用项目属性->项目引用标记所有引用的项目(在工作空间中)