Compiler Defines and Eclipse Editor Highlighting

In this post I have found settings for Eclipse Indexer to show the state if defines correctly. Usually I have something like this in my projects:

debug me

debug me

So I define the macro DEBUG_ME on the compiler command line. And it is cool to see that the Eclipse editor correctly grays out the code which is not enabled. But for this the Eclipse Editor view needs to know about the macro, but how does this work?

The reality is: that works out of the box for many tool chains, but not for all.

Kinetis ARM gcc

It works perfectly for the ARM gcc as in MCU10.3. And it works because the editor knows that this symbol is defined in the Path and Symbols information of the project:

Path and Symbols with DEBUG_ME

Path and Symbols with DEBUG_ME

This, because this symbol is added automatically to the symbols list, because I have defined it in the compiler preprocessor settings for the Kinetis ARM gcc compiler:

Compiler preprocessor

Compiler Preprocessor

Without going into the details: The Eclipse Managed Make framework and option settings offers the above -D control, and if used by the build tool panels, the options are automatically added/removed from the symbols.

Freescale (non-gcc) ARM/Kinetis Compiler

That feature exists as well for the Freescale (non-gcc) ARM/Kinetis compiler under ARM Compiler > Input:

Freescale ARM Compiler Input

Freescale ARM Compiler Input

Freescale S08 Compiler

The same thing is found for the S08 compiler under HCS08 Compiler > Preprocessor:

HCS08 Preprocessor

HCS08 Preprocessor

Freescale ColdFire Compiler

Unfortunately (at least up to MCU10.3 beta) such a panel is not present for the Freescale ColdFire compiler. I can use the -d compiler option to pass my defines:

ColdFire define

ColdFire define

But: this has no meaning for the Eclipse editor. The compiler knows about the symbol, but not the Editor view. And because this managed make integration into eclipse is not using the panels as shown above, the # Symbols tab is missing too, so I cannot add manually a symbol? 😦

Missing Symbols Tab

Missing Symbols Tab

I have filed a feature request, so hopefully this could be added. Until then, the Eclipse editor view is innocent and does not know what I have defined on the compiler side.

💡 If you have found a solution for that problem, then please post a comment 🙂

PowerPC Compiler

A similar story for the PowerPC compiler. There is no separate settings for preprocessor defines, but can be added using the -d option as shown below:

Define option for a PowerPC project

Define option for a PowerPC project

The option -d DEBUG_ME=1 is equivalent to have

#define DEBUG_ME 1

in all sources. What that compiler Eclipse integration offers is to specify a prefix file: instead of passing the defines on the command line, they are put in a normal text file:

Preprocessor prefix files

Preprocessor prefix files


The way how to specify compiler defines is different from compiler to compiler. At least there is a command line options common to all of them. But only using the Eclipse CDT special panel for defines ensures that Eclipse is aware of the symbol definition.

Happy Defining 🙂

15 thoughts on “Compiler Defines and Eclipse Editor Highlighting

  1. Hello Erich

    Did get a quick look at this one.
    When building for Coldfire V2 or V3, if you want to get correct conditional code display in your source code you can use a prefix file instead of using -d option to define your macro.

    For instance to define a macro called DEBUG_ME, just create a file prefix.h and specify it as prefix file in the C/C++ Build > Settings > Coldfire Compiler > Input page.

    The prefix file should include #define statement for the macros you want to define and also include the default prefix file.

    To retrieve the name of the prefix file preprocess one of your source file. The default prefix file might be lib_ewl.prefix or lib_c99.prefix.
    These files are stored in {Install}\MCU\ColdFire_Support\ewl\EWL_C\include folder.

    I agree with you that adding a new edit box similar to what has been done for HCS08 or ARM is more elegant. But until this gets implemented, you can work with a prefix file.


  2. Were you able to resolve this issue? I am having a similar problem. I need to add include paths so that the indexer can recognize all of my symbols, but for some reason when I go to Project Properties -> C/C++ General -> paths and symbols I can not see the Includes or the Symbols tabs. The tabs seem to be visible in one version of eclipse, but not another. This seems to be a common problem. I see lots of hits when searching for a solution, but no explanation of how to resolve it. Thanks for the help.



  3. Using the excellent GNU Arm Eclipse plugin (using Eclipse Mars), I see 4 places to put compiler preprocessor define symbols:
    1) C/C++ Build -> Settings -> Cross Arm C or C++ Compiler -> Preprocessor
    2) C/C++ Build -> Build Variables
    3) C/C++ General -> Paths and Symbols -> Symbols
    4) C/C++ General -> Preprocessor Include Paths, Macros etc.

    #3 is the place that Eclipse CDT documentation “Adding Include paths and symbols in Managed Build System” says to use.

    All but #1 allow for different symbols for different Build Configurations.

    Not sure why there are so many places to do this in the Eclipse CDT user interface. There is little documentation on why to use one place versus another. Unless someone has better advice, I will use #3 above because it has the most authoritative documentation.


  4. In testing the behavior, 3) is propagated from 1), and also 1) is propagated from 3), so it appears 1) and 3) are equivalent, so either can be updated by the user with the same result. Thanks for explaining to me that 2) is something completely different.


  5. With Tasking Compiler for Tricore I solved this issue enabling specific indexer settings into C/C++ General – Indexer settings.

    You need to tell the indexer to start again when swapping build configurations.

    -> Enable specific settings
    -> Store settings with project
    -> Index unused headers
    -> Use active build configuration
    -> Reindex project on change of active build configuration


What do you think?

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.