1

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"/>
4
  • 1
    That's the correct syntax, and it works fine in a test: godbolt.org/z/dxoxMa3rc. So probably the -D option is not actually making it to the compiler; I'm not familiar with this IDE so I'm not sure if where you've added this option is the right place. One note is that what you're defining is not a symbol (which is a name resolved to an address at link time) but rather a macro (which is only used in preprocessing); any chance that confusion is related? Commented Mar 28, 2021 at 16:42
  • @NateEldredge, I guess you're right. I've update the question. Commented Mar 29, 2021 at 4:44
  • Using the "avr-as-pre" section is suspect unless you actually have assembly-language files in your project. "avr-as" is the name of the GNU assembler for AVR. Commented Mar 29, 2021 at 18:34
  • @DavidGrayson, that makes sense. I was betrayed by the pre suffix - I guessed it stands for preprocessor but I didn't think about the as part! Commented Mar 29, 2021 at 18:48

1 Answer 1

3

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

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.