微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

从代码中找不到编译器定义的符号

如何解决从代码中找不到编译器定义的符号

我在 MPLAB X IDE v5.45 下使用 AVR GCC 编译器 v5.4.0。 我在 avr-as-pre 部分为编译器定义了一个符号。它将以下内容添加调用的命令中:

-DF_cpu=32000000UL

代码里面我有一些这样的检查:

#ifndef F_cpu
    // do something

它实际上做了某事。看起来好像没有找到符号。 如何以这种方式为整个项目定义一个符号,我错了吗?

更新

IDE 将这些东西称为“定义的符号”:

enter image description here

但它实际上将它们存储为“预处理器宏”:

  <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>

不幸的是,它似乎没有将它们传递给编译器:

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

解决方法

您必须在 avr-gcc > Preprocessing and messages > Defined symbols 部分下定义编译器符号:

enter image description here

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。