Issue
After a recent upgrade (only SSD capacity change), Eclipse CDT Indexer has been giving me a tough time. My project folder structure is as shown below.
LinEmLibrary
└─ test
├─ TestNumParam.cpp
├─ TestNumParam.h
├─ TestPMS.cpp
├─ TestPMS.h
├─ TestSerial.cpp
├─ TestSerial.h
├─ TestWindow.cpp
└─ TestWindow.h
TestWindow.h
has the class implementing the top level window and the other three are instantiated by the class CTestWindow
.
After the upgrade (until which things were running perfectly), Codan (code analysis) started highlighting the declarations of all of my class instances (CTestNUmParam
, CTestPMS
and CTestSerial
) in red saying Type X could not be resolved. However I am able to perform code completion (CTRL+SPACE) and resolve all members of the class though it takes a painfully long amount of time. The code builds and executes properly.
I have tried
- rebuilding the index
- Increased the Indexer cache limits (Window > Preferences > C/C++ > Indexer - Cache limits) to,
- Limit relative to the maximum heap size: 75%
- Absolute limit: 1024 MB
- Set the initial and maximum heap size in
eclipse.ini
to- Xms2048m
- Xmx4096m
- adding absolute path to this folder in the Project Settings > C/C++ General > Paths and Symbols and even include my header using <> instead of ""
- create a new project and manually copy the files to the new project
- export the project and open in another computer having same build tools
But in all cases the result is the same.
When I create a parse log for TestWIndow.h
(right click on the header file in project explorer, Index > Create Parser Log File) I get the following output (first ~12,000 lines removed).
Unresolved includes (from headers in index):
file:/home/mohith/eclipse_workspace/LinEmLibrary/test/TestNumParam.h is not indexed
file:/home/mohith/eclipse_workspace/LinEmLibrary/test/TestPMS.h is not indexed
file:/home/mohith/eclipse_workspace/LinEmLibrary/test/TestSerial.h is not indexed
Unresolved names:
Attempt to use symbol failed: CTestNumParam in file /home/mohith/eclipse_workspace/LinEmLibrary/test/TestWindow.h:76
Attempt to use symbol failed: CTestPMS in file /home/mohith/eclipse_workspace/LinEmLibrary/test/TestWindow.h:77
Attempt to use symbol failed: CTestSerial in file /home/mohith/eclipse_workspace/LinEmLibrary/test/TestWindow.h:78
A template id provides illegal arguments for the instantiation: map in file /home/mohith/eclipse_workspace/LinEmLibrary/test/TestWindow.h:80
Attempt to use symbol failed: EGridType in file /home/mohith/eclipse_workspace/LinEmLibrary/test/TestWindow.h:80
The reason for the semantic highlighting is now understood from this but why the indexer is not including my own header files leaves me clueless.
Would be a great help if someone can shed some light.
My system information
Eclipse
Version: 2021-09 (4.21.0)
Build id: 20210910-1417
CDT: 10.4.0.202109080104
OS Ubuntu 20.04 x86-64
RAM: 16 GiB
CPU: Intel® Core™ i5-8265U CPU @ 1.60GHz
Solution
After a month of struggle I have finally broght things back to normal.
The issue appears to be the preferences I would import after creating a new workspace. I have exported preferences once after setting up the environment for code style, editor font / color etc. I don't remember exactly but I might have created it while running Eclipse 2021-03.
This time I created a new workspace and added the project from SVN without importing preferences and viola... all my headers are indexed! Later I individually exported the code style and other templates and brought it into my new workspace without any issues.
I was also facing issue with Log4CPlus where all its macros were marked as 'symbol not resolved'. Upon inspecting the parser log file I saw that the symbol __cplusplus
was set to 201402
even though I had selected c++20 as the dialect in build settings. Then I added the symbol __cplusplus
manully in Project Settings > C/C++ General > Paths and Symbols > Symbols > GNU C++ while settings it to 202002. That fixed the issue with Log4CPlus as well.
Answered By - Mohith