简体   繁体   English

在整个项目中搜索包含在 Eclipse CDT 中

[英]Search entire project for includes in Eclipse CDT

I have a large existing c++ codebase.我有一个庞大的现有 c++ 代码库。 Typically the users of the codebase edit the source with gvim, but we'd like to start using the nifty IDE features in Eclipse.通常,代码库的用户使用 gvim 编辑源代码,但我们想开始使用 Eclipse 中漂亮的 IDE 功能。 The codebase has an extensive directory hierarchy, but the source files use include directives without paths due to some voodoo we use in our build process.代码库有一个广泛的目录层次结构,但由于我们在构建过程中使用了一些巫术,源文件使用了没有路径的包含指令。 When I link the source to my project in Eclipse, the indexer complains that it can't find any header files (because we don't specify paths in our includes.) If I manually add the directories from the workspace to the include path then everything works wonderfully, but obviously adding hundreds of directories manually isn't feasible.当我在 Eclipse 中将源链接到我的项目时,索引器抱怨它找不到任何头文件(因为我们没有在包含中指定路径。)如果我手动将工作区中的目录添加到包含路径,那么一切都很好,但显然手动添加数百个目录是不可行的。 Would there be a simple method to tell Eclipse to look anywhere in the project for the include files without having to add them one by one?是否有一种简单的方法可以告诉 Eclipse 在项目中的任何位置查找包含文件,而不必一个一个地添加它们? If not, then can anyone suggest a good starting place, like what classes to extend, for writing a plugin to just scan the project at creation/modification and programatically add all directories to the include path?如果没有,那么任何人都可以建议一个好的起点,比如要扩展哪些类,编写一个插件来在创建/修改时扫描项目并以编程方式将所有目录添加到包含路径?

The way that CDT manages build paths is by looking at the .cdtbuild xml file in the base of your projects directory (it might be a different name on windows... not sure) CDT 管理构建路径的方式是查看项目目录基础中的 .cdtbuild xml 文件(它在 Windows 上可能是不同的名称......不确定)

In this you should see something like在这你应该看到类似

<option id="gnu.c.compiler.option.include.paths....>
<listoptionValue builtIn="false" value="&quot;${workspace_loc:/some/path}$quot;" />
<listOptionValue ... />

...
</option>

this is where all the build paths that you configure in the gui are placed.这是放置您在 gui 中配置的所有构建路径的位置。 It should be pretty easy to add all the directories to this using a simple perl script to walk the project and generate all the listOptionValue entries.使用简单的 perl 脚本来遍历项目并生成所有 listOptionValue 条目,将所有目录添加到此应该很容易。

This is obviously not the ideal method.这显然不是理想的方法。 But im curious, what build system are you migrating from, if it is make based you should be able to get eclipse to use your make files.但我很好奇,你从什么构建系统迁移,如果它是基于 make 的,你应该能够让 eclipse 使用你的 make 文件。

This feature has already been implemented in the current CDT development stream and will be available in CDT 6.0, which will be released along with Eclipse 3.5 in June 2009.此功能已在当前的 CDT 开发流程中实现,并将在 CDT 6.0 中提供,CDT 6.0 将于 2009 年 6 月与 Eclipse 3.5 一起发布。

Basically if you have an #include and the header file exists somewhere in your project then CDT will be able to find it without the need to manually set up include paths.基本上,如果您有一个#include 并且头文件存在于您的项目中,那么 CDT 将能够找到它,而无需手动设置包含路径。

If you need the feature now you can download and install the latest CDT development build.如果您现在需要该功能,您可以下载并安装最新的 CDT 开发版本。

Eclipse Bugzilla: https://bugs.eclipse.org/bugs/show_bug.cgi?id=213562 Eclipse Bugzilla: https ://bugs.eclipse.org/bugs/show_bug.cgi?id=213562
Latest CDT 6.0 Builds: http://download.eclipse.org/tools/cdt/builds/6.0.0/index.html最新的 CDT 6.0 构建:http: //download.eclipse.org/tools/cdt/builds/6.0.0/index.html

From reading the this Eclipse CDT FAQ entry , it sounds like Eclipse can automatically generate a list of include directories if you start your build from within Eclipse and if your build outputs the gcc / g++ commands before actually starting gcc / g++ .从阅读这个 Eclipse CDT FAQ 条目,听起来 Eclipse 可以自动生成包含目录的列表,如果您从 Eclipse 中启动构建并且如果您的构建在实际启动gcc / g++之前输出gcc / g++命令。 You can change how Eclipse starts a build by going under Project Properties then selecting the C/C++ Build category and looking for the Build Command option on the right side of the dialog.您可以通过在 Project Properties 下选择 C/C++ Build 类别并在对话框右侧查找 Build Command 选项来更改 Eclipse 启动构建的方式。

Depending on the amount of voodoo you are doing in your build process, then Eclipse may not be able to correctly parse your source files, especially if you have similarly named headers for different source files.根据您在构建过程中执行的 voodoo 数量,Eclipse 可能无法正确解析您的源文件,尤其是当您为不同的源文件具有类似命名的标头时。 If you really want to take full advantage of Eclipse you're going to need to make sure that with whatever setup you have you aren't going to be confusing the parser.如果您真的想充分利用 Eclipse,您将需要确保无论您有什么设置,您都不会混淆解析器。 Personally I would recommend having a simple layout and build process.我个人建议有一个简单的布局和构建过程。

As for the question at hand, adding the directories one by one is pretty much your best bet.至于手头的问题,一一添加目录几乎是您最好的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM