Mark
Mark

Reputation: 5038

Compiler defined symbol not found from code

I'm using AVR GCC compiler v5.4.0 under MPLAB X IDE v5.45. I defined a symbol for the compiler in the avr-as-pre section. It adds the following to the invoked command:

-DF_CPU=32000000UL

Inside the code I have some checks like this:

#ifndef F_CPU
    // do something

and it actually does something. It looks like if it doesn't find the symbol. Am I wrong about how to define a symbol for the whole project in this way?

UPDATE

The IDE calls this stuff "defined symbols":

enter image description here

but it stores them as "preprocessor macros" actually:

  <AVR-AS-PRE>
    <property key="announce-version" value="false"/>
    <property key="include-paths" value=""/>
    <property key="preprocessor-macros" value="F_CPU=32000000UL"/>
    <property key="preprocessor-macros-undefined" value=""/>
    <property key="suppress-warnings" value="false"/>
  </AVR-AS-PRE>

Unfortunately it seems it does not pass them to the compiler:

$ grep -nrw . -e F_CPU
./nbproject/configurations.xml:117:        <property key="preprocessor-macros" value="F_CPU=32000000UL"/>

Upvotes: 1

Views: 454

Answers (1)

Mark
Mark

Reputation: 5038

You have to define the compiler symbols under avr-gcc > Preprocessing and messages > Defined symbols section:

enter image description here

Upvotes: 3

Related Questions