Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I convince Eclipse CDT that a macro is defined for source code editing and code completion?

I have in my source code:

// foo.cpp
struct foo
{
  foo() {}

  #ifdef I_WANT_THIS_FEATURE
  void bar() {}
  #endif
};

In my Makefile I have

foo.o: foo.cpp
        g++ -c -DI_WANT_THIS_FEATURE foo.cpp -o foo.o

This compiles fine from the command line as well as with the external builder that I have created in Eclipse (which basically defines a few environment variables and calls make) and I can call foo::bar().

However, in the Eclipse CDT source code editor, the part where I define foo::bar() has a grey background (suggesting that foo::bar() would not be included in the build) and code completion on objects of type foo does not suggest bar() as a method that can be called.

How can I define the I_WANT_THIS_FEATURE macro in an Eclipse CDT makefile project with custom makefile so that it is known to the source code editor and the code completion?

like image 383
Oswald Avatar asked Feb 15 '23 14:02

Oswald


2 Answers

In addition to Oswald's answer:

If you have several build configurations, the default behavior of the Eclipse Indexer seem to be that it always uses the first build configuration.

In my case the define was only defined in the 3rd build configuration, so the solution provided by Oswald did not help.

To change this globally, select Window -> Preferences -> C/C++ -> Indexer. Choose Use active build configuration

You could also choose to override the global settings in the project settings under Project -> Properties -> C/C++ General -> Indexer and select Enable project specific settings followed by selecting Use active build configuration.

After this, the solution provided by Oswald should work:

Project -> Properties -> C/C++ General -> Paths and Symbols

Choose the Symbols tab and Add... a new Symbol with Name I_WANT_THIS_FEATURE and a Value of 1.

like image 130
Bimme Avatar answered Apr 29 '23 07:04

Bimme


Found it: Project -> Properties -> C/C++ General -> Paths and Symbols

Choose the Symbols tab and Add... a new Symbol with Name I_WANT_THIS_FEATURE and a Value of 1.

like image 30
Oswald Avatar answered Apr 29 '23 05:04

Oswald