67

I'm using Eclipse with C++ code via linked resources on Linux. The code analysis index seems to be corrupted (Goto definition lands the cursor close to, but not on, the definition) Refreshing resources doesn't fix it, neither does restarting Eclipse.

Is there a way to flush the index and rebuild it?

Josh Kelley
  • 56,064
  • 19
  • 146
  • 246
Vincent Scheib
  • 17,142
  • 9
  • 61
  • 77

9 Answers9

84

Right-click on your project, go under the Index submenu, and choose either "Rebuild," "Update with modified files," or "Freshen all files."

I don't know the difference between those three options, but one of "Update with modified files" or "Freshen all files" usually fixes it for me.

Also, I'm sure you've already done this, but make sure that you're running the latest version of the Eclipse CDT. Current versions seem to have much more reliable indexing than previous versions.

Josh Kelley
  • 56,064
  • 19
  • 146
  • 246
  • 2
    In the past I've also had to sometimes close and reopen the project to get this to take for some reason. – Michael Burr Jun 09 '10 at 17:51
  • 2
    "Freshen all files" worked well. "Rebuild" did not help. – tutejszy Jan 16 '17 at 13:30
  • More importance should be given to "freshen". I rebuilt several times after changing c++11 to c++14 in several places so that `__cplusplus__` would be 201300 so in turn I can have make_unique. Freshen was the step I needed, after all those rebuilds. – cardiff space man Jun 01 '18 at 01:02
  • "Rebuild" worked for me - I was specifically using Simplicity Studio 5 (a Silicon Labs derivative of Eclipse) and a symbol was getting the red squiggle underneath. – Frederick Aug 12 '23 at 15:31
37

From http://dev.eclipse.org/mhonarc/lists/cdt-dev/msg10390.html, the differences between "Rebuild," "Update with modified files," or "Freshen all files":

Rebuild: Works for entire projects, only. Clears the index and indexes the files from scratch. When cancelled it leaves you with an empty or partial index.

Update with Modified Files: Works on a resource selection. Checks on individual files whether the timestamp or the scanner-config has been changed and updates the index for the changed files.

Freshen All Files: Works on a resource selection. Updates the selected files in the index. The index is not cleared, it is safe to cancel the operation.

Stephen
  • 479
  • 4
  • 5
  • 4
    While this is not an answer to the question, this was still helpful. – Axle Sep 04 '13 at 13:39
  • 1
    This description matches what I would expect, but does not match what I actually see from the behavior of Eclipse. For me "Freshen All Files" fixed the problem but "Rebuild" did not. This does not make any sense if "Rebuild" really deletes the index and builds it again from scratch. – Ben May 24 '17 at 16:03
22

Go to your project properties -> C++ general -> Indexer.

  • Do this with 'project specific settings',
    (or on 'Configure Workspace Settings...').
  • Deselect 'Enable Indexer' hit Apply.
  • Select 'Enable Indexer' hit Apply.

This should completely wipe out and rebuild the index.

Andy Hayden
  • 359,921
  • 101
  • 625
  • 535
TheAnvil
  • 221
  • 2
  • 2
  • Thanks. This helped. Additionally I needed to select the 'Index Source Files Not Included In The Build' option. This is because my build environment/ toolchain is not integrated within eclipse (i.e. eclipse is used only for browsing and editing code but not for building the project). – venk Apr 14 '21 at 09:59
17

Neither of the above worked for me (Eclipse Indigo), index still broken and refusing to rebuild properly. Until applied this one:

http://slsam2.blogspot.com/2012/02/eclipse-cdt-index-not-working.html

The crucial bit of the linked post is this:

Eclipse no longer treats your project as a C++ project. Choose menu File/New/Convert to a C/C++ project. It takes a while to index the source code.

I still wonder how Eclipse can uncontrollably shoot itself in the foot like that. I suspect that installing additional packages can trigger it. Perhaps JavaScript support in my case.

skrrgwasme
  • 9,358
  • 11
  • 54
  • 84
Pavel Zdenek
  • 7,146
  • 1
  • 23
  • 38
  • 1
    Much appreciate not only posting a link, but saving off the relevant info for if/when links break again. This should be a requirement for StackOverflow answers. – dwanderson Nov 11 '15 at 22:06
  • @dwanderson It is: http://meta.stackexchange.com/questions/225370/your-answer-is-in-another-castle-when-is-an-answer-not-an-answer – skrrgwasme Dec 12 '16 at 20:03
  • 1
    only this one worked for me for Eclipse Version: 2019-03 (4.11.0). Thanks – alphaGeek Aug 19 '19 at 10:25
  • This was the only solution that worked for me (4.12.0). – Z boson Dec 05 '19 at 11:05
7

delete only the .pdom file under .metadata.plugins\org.eclipse.cdt.core helps, I got the indexer screwed after upgrading Neon.2 to Neon.3 and this seems to solve the problem. (this comment already exists above but am not allowed to confirm it up there).

Shay Perlstein
  • 141
  • 1
  • 4
  • This has worked for me! I had a strange bug in an IDE based on eclipse that caused eclipse to hang on startup and use up a ton of memory (but I was able to tell that the index is corrupt), so Josh's answer was not practical for me. – 9a3eedi Jan 08 '20 at 09:02
  • I needed to delete also the .xml file there to get it to work – arye Jan 04 '23 at 07:38
2

I found that I had the global indexer set to 'Use the build configuration specified in the project's indexer settings', and the project's indexer set to NOT use project specific indexer settings. Regardless, it was using the same fixed configuration for the indexer regardless of which configuration I had selected. The fix: Window-Preferences, C/C++, Indexer. Select "Use active build configuration" in section "Build configuration for the indexer".

Happy days.

radsdau
  • 495
  • 5
  • 16
1

Eclipse no longer treats your project as a C++ project. Choose menu File/New/Convert to a C/C++ project. It takes a while to index the source code. worked for me

kibrom
  • 19
  • 1
1

Did you try adding -clean to the command line for the eclipse executable?

Chris Dennett
  • 22,412
  • 8
  • 58
  • 84
0

I started with trying Josh Kelleys and mmmmms answers without any luck, but I finally fixed it by checking my include paths.

One way to see them are in the Project Explorer, expand project and there should be an entry "Includes". Inside that, check for a small yellow warning triangle on each include path. If that triangle is present eclipse most likely doesn't recognize the path.

The include paths are edited through right-clicking on "Your project" in the Project explorer, then choose "Properties" --> C/C++ General --> Paths and Symbols --> Includes.

I see three language options, Assembly, Gnu C, Gnu C++. Choose the correct one before starting to add paths (likely Gnu C++). After adding all the paths, -->Apply --> Ok and rebuild index if you're asked to.

My erroneous workspace paths looked like MyProject/MyProject/folder when it was supposed to be MyProject/folder.

For me the "Problems"-view is always slow to update, even after rebuilding index. To be sure that the error is still there, double-click the problems entry so that eclipse opens/reloads the file in question. This often seems necessary for me to update the "Problems" view.

I don't really know if it was eclipse or my scm that messed it up. Anyway, hope it helps someone!

I use Luna and builds with an external makefile.

Schaki
  • 1,697
  • 1
  • 12
  • 14