在整个项目中搜索包含在 Eclipse CDT 中的内容
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/274066/
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
Search entire project for includes in Eclipse CDT
提问by Jonesinator
I have a large existing c++ codebase. Typically the users of the codebase edit the source with gvim, but we'd like to start using the nifty IDE features in Eclipse. 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. 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? 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?
我有一个大型的现有 C++ 代码库。通常,代码库的用户使用 gvim 编辑源代码,但我们希望开始使用 Eclipse 中漂亮的 IDE 功能。代码库具有广泛的目录层次结构,但由于我们在构建过程中使用了一些巫毒教,源文件使用不带路径的包含指令。当我在 Eclipse 中将源链接到我的项目时,索引器抱怨它找不到任何头文件(因为我们没有在我们的包含中指定路径。)如果我手动将目录从工作区添加到包含路径然后一切都很好,但显然手动添加数百个目录是不可行的。是否有一种简单的方法可以告诉 Eclipse 在项目中的任何位置查找包含文件,而无需逐个添加它们?如果不,
采纳答案by Mike Kucera
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=21356
Latest CDT 6.0 Builds: http://download.eclipse.org/tools/cdt/builds/6.0.0/index.html
Eclipse Bugzilla: https://bugs.eclipse.org/bugs/show_bug.cgi?id=21356
最新的 CDT 6.0 版本:http://download.eclipse.org/tools/cdt/builds/6.0.0/index.html
回答by luke
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=""${workspace_loc:/some/path}$quot;" />
<listOptionValue ... />
...
</option>
this is where all the build paths that you configure in the gui are placed. 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.
这是您在 gui 中配置的所有构建路径所在的位置。使用简单的 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 文件。
回答by Josh Kelley
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++
. 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.
通过阅读此 Eclipse CDT FAQ 条目,听起来 Eclipse 可以自动生成包含目录列表,如果您从 Eclipse 内开始构建并且您的构建在实际启动/之前输出gcc
/g++
命令。您可以通过转到 Project Properties 下,然后选择 C/C++ Build 类别并查找对话框右侧的 Build Command 选项来更改 Eclipse 启动构建的方式。gcc
g++
回答by Mark Kegel
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. 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. Personally I would recommend having a simple layout and build process.
根据您在构建过程中执行的 voodoo 数量,Eclipse 可能无法正确解析您的源文件,尤其是当您对不同的源文件具有类似命名的标头时。如果你真的想充分利用 Eclipse,你需要确保无论你有什么设置,你都不会混淆解析器。我个人建议有一个简单的布局和构建过程。
As for the question at hand, adding the directories one by one is pretty much your best bet.
至于手头的问题,一个一个地添加目录几乎是你最好的选择。