Vassilis Papanikolaou
Vassilis Papanikolaou

Reputation: 132

Make Eclipse CDT pre-include a header file, to avoid error: "Symbol <symbol> could not be resolved"

Is there a way to make the Eclipse editor presume that a specific C header file has already been included, without having to #include it explicitly?

For example, how can we achieve:

#include "common_type_defs.h"
#include "special_type_defs.h" // Don't want to have to mention this header file

main()
{
  common_type var1;
  special_type var2;
  .....
}

by writing only:

#include "common_type_def.h"

main()
{
  common_type var1;
  special_type var2; // Eclipse editor: "Symbol 'special_type' could not be resolved"
  .....
}

without getting the Eclipse editor annotation error: "Symbol 'special_type' could not be resolved".

The reason is, the project uses a custom scripted build system. The special header files are added automatically by the build system, selected from different libraries. So the build succeeds.

I have added the special header folder to the include paths of the project. This allows me to hit [F3] and jump to the definition of "special_type". It is just that the editor flags an error.

I do not want to silence the error because I want to catch real errors.

Any suggestions?

Upvotes: 3

Views: 1425

Answers (3)

JD.
JD.

Reputation: 475

Go to:
Project propertiesC/C++ GeneralPreprocessor Include Paths, Macros etc.EntriesGNU C
Select CDT User Setting Entries and than click Add button. Select Include File and enter your preprocessor pre-include file here.

Apply and rebuild indexer.

My pre-included ppdefs.h file

I am using Oxygen.1a Release (4.7.1a)

Upvotes: 1

Vassilis Papanikolaou
Vassilis Papanikolaou

Reputation: 132

I ended up creating different "build configurations", for each build option of the build system. There I can add the background header files, as required.

One disadvantage is that I must maintain the different build configurations to mirror the build system: when new header files are added to the build system, the same files must also be added to the eclipse build configuration. So this solution will be unsuitable for big team projects where multiple people frequently change the included files because you could easily miss a file change or two. But it works well for small teams and infrequent changes.

Upvotes: 0

wiesniak
wiesniak

Reputation: 583

Do additional define in your build system and then:

#ifndef CUSTOMBUILDER
#include "special_type_defs.h" // Don't want to have to mention this header file
#endif

Upvotes: 1

Related Questions