26

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

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

 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.

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.

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.

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?

Puppy
  • 144,682
  • 38
  • 256
  • 465
Gordon
  • 1,210
  • 5
  • 16
  • 23
  • I know this isn't an answer, but you might want to Google "Recursive Make Considered Harmful". :-) – R.. GitHub STOP HELPING ICE Sep 01 '11 at 16:48
  • 2
    And if I had the authority to refactor the entire source tree, I might, but sometimes that isn't an option when you work for someone else. In addition, I don't think this is an unreasonable request of Eclipse! :) – Gordon Sep 01 '11 at 17:59
  • 4
    Have you added each of the directories containing headers to the project's Include Headers setting? You should also double-check the Indexer and Project settings to ensure you aren't ignoring anything. Then try rebuilding the index (right-click, Index, Rebuild). – Ioan Sep 01 '11 at 19:08
  • I can't add directories to the headers in the Include Headers setting because this isn't a C or C++ project. In fact, the source tree includes Java and C code. I have a separate Java project that is pointing to the single subdir that contains the Java code, but I'm hoping I don't have to set up a separate C project pointing to each of the 50 subdirs that contains C code in it just so the indexer can work. And finally, the Indexer option isn't available in non-C projects evidently. – Gordon Sep 02 '11 at 14:38

13 Answers13

32

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

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.

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.

MHD
  • 321
  • 3
  • 3
  • 4
    This worked for me, note though that the option moved from that window to the context-menu of the project itself, at least in Eclipse Kepler. So I did (in C/C++ view) right-click on the project, choose `New` -> `Convert to C/C++ Project (Adds C/C++ Nature)`. There I chose `Executable` and `Linux GCC`. I can browse around my code now. – Bart Friederichs Jul 15 '14 at 12:07
  • https://stackoverflow.com/a/9182742/4361073 + https://stackoverflow.com/a/7663879/4361073 (after your project has been converted into the C++-Project Type. – parasrish Mar 15 '18 at 04:37
11

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

Jav_Rock
  • 22,059
  • 20
  • 123
  • 164
Somabho
  • 111
  • 1
  • 5
  • This would work, only if "project type" is being set (otherwise will be disabled). One has to follow https://stackoverflow.com/a/11459213/4361073 (as above), and then this to re-index. – parasrish Mar 15 '18 at 02:59
5

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.

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.

Gordon
  • 1,210
  • 5
  • 16
  • 23
  • 1
    Indexing is different than syntax highlighting. Syntax highlighting is simple because it only depends on keywords. Indexing requires knowing how the source will be compiled/executed to correctly work. – Ioan Sep 02 '11 at 17:15
4

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

CppChase
  • 901
  • 12
  • 25
3

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

2

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.

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.

2

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

  • go to File
  • New
  • Convert to C/C++ Autotools project then select your project and finish.

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

Venom
  • 1,010
  • 10
  • 20
1

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.

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

0

In Coocox IDE (Eclipse + gcc) the problem is resolved by going from file menu Edit > Preferences > C/C++ / Indexer > Build configuration for Indexer set to Active build configuration and the rebuild the project (Ctrl R).

jim
  • 1
  • 1
0

If the project is already converted to C/C++ and still the index is not working you can right click on the project and Index and rebuild. The project will start indexing right away.

hegu2212
  • 1
  • 2
0

I am using

Eclipse IDE for C/C++ Linux Developers

Version: Helios Service Release 2 Build id: 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

0

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.

yep
  • 3
  • 1
0

Please try the following (my project is set up differently, so I am not sure this will work for you).

Go to Properties -> C/C++ General -> Paths and Symbols -> Source Location.

Do you see your source folder there?

I observe this behavior: When I add a source folder and then exclude it from build, it disappears from the above list. After that the folder is no longer indexed. Re-adding it to "Source Location" solves the problem: the folder is now indexed; remains excluded from build (as intended); is visible among source locations.

I believe it is a bug -- excluding a source folder from build should not remove it from source locations list.

user443854
  • 7,096
  • 13
  • 48
  • 63
  • That option is only available in a C project, and this source tree contains C and Java code. – Gordon Sep 02 '11 at 14:38