Search entire project for includes in Eclipse CDT

10,171

Solution 1

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.

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.

If you need the feature now you can download and install the latest CDT development build.

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

Solution 2

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)

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. 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.

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.

Solution 3

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.

Share:
10,171
Jonesinator
Author by

Jonesinator

Updated on June 17, 2022

Comments

  • Jonesinator
    Jonesinator almost 2 years

    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?

  • Evgeny
    Evgeny over 15 years
    I have just tested this -- it works in the most uncomfortable way. It is parsing the build log, and adds include paths from g++ -I/some/path lines into "system includes". Using the .cproject file and adding them yourself, allow to have it versiones in VC. Auto-Discovery does not.