【问题标题】:avr-gcc: variable must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’avr-gcc:变量必须是 const 才能通过“__attribute__((progmem))”放入只读部分
【发布时间】:2014-02-08 15:28:16
【问题描述】:

我正在尝试重现此 4-key-keyboard ,为此我正在尝试通过在我的 Linux 机器上使用 avr-gcc 编译 its source

我设法通过使用参数扩展命令行来解决编译器抛出的几个错误,但现在我遇到了以下错误。问题是V-USB 上的很多演示项目使用相同的库并抛出相同的错误,我不想通过所有代码来尝试为我想要检查的每个项目修复它们。我意识到最好的方法是修复源代码中的错误,但是尽管可以轻松解决以下错误,但会引发新的错误,解决的所有更改要复杂得多我无法保证生成的程序仍然可以正常工作。

我的问题是:avr-gcc 是否有一些兼容性命令行参数可以让代码像旧版本的 gcc 一样编译?

这是我用来编译源代码的命令:

avr-gcc main.c -I /usr/lib/avr/include/ -mmcu=attiny85 -DF_CPU=16000000 -Os -I ./usbdrv

这些是 avr-gcc 抛出的错误:

In file included from main.c:32:0:
./usbdrv/usbdrv.h:455:6: error: variable ‘usbDescriptorDevice’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
./usbdrv/usbdrv.h:461:6: error: variable ‘usbDescriptorConfiguration’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
./usbdrv/usbdrv.h:467:6: error: variable ‘usbDescriptorHidReport’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
./usbdrv/usbdrv.h:473:6: error: variable ‘usbDescriptorString0’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
./usbdrv/usbdrv.h:479:5: error: variable ‘usbDescriptorStringVendor’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
./usbdrv/usbdrv.h:485:5: error: variable ‘usbDescriptorStringDevice’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
./usbdrv/usbdrv.h:491:5: error: variable ‘usbDescriptorStringSerialNumber’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
main.c:105:14: error: variable ‘usbDescriptorHidReport’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’

我的配置:

Ubuntu 13.10

avr-gcc (GCC) 4.7.2

【问题讨论】:

    标签: gcc avr-gcc


    【解决方案1】:

    我知道这篇文章有点站不住脚。但这可能会对某人有所帮助。

    该错误的原因是新的 avr-gcc 需要 PROGMEMconst。您只需要将 const 放在以 PROGMEM 开头的每一行前面。

    Sedsed -i 's/^PROGMEM/const PROGMEM/g' usbdrv/* 很好地解决了这个问题。

    【讨论】:

      【解决方案2】:

      usbdrv/ 目录需要更新到最新版本。下载 V-USB tarball 或 zip 文件并将项目的 usbdrv/ 替换为存档中的那个。您可能需要稍微修改一下项目的usbconfig.h,以使新的 V-USB 与现有项目一起工作,尽管大多数情况下它应该可以工作。

      【讨论】:

      • 是的,那是我正在使用的支线,但这会引发另一个错误,如果我不能解决这个问题,可能值得另一个问题。
      • 让我的 USB 音量控制键盘正常工作了 :o) 我更新了过时的库,并经过一番摆弄,我得到了编译。
      【解决方案3】:

      你没有给出错误出现的代码,但是仅仅看到错误信息,问题就很清楚了

      ./usbdrv/usbdrv.h:455:6: error: variable ‘usbDescriptorDevice’ must be const in order to be put into read-only section by means of ‘__attribute__((progmem))’
      

      您只能将 constants 放在只读部分(例如 flash)。所有变量都进入 RAM。因此,如果您希望“usbDescriptorDevice”(我不知道它的作用)进入只读部分(因为您正在放置“progrmem”),您应该将其声明为常量。

      问题通常出现在不符合这个简单规则的旧库中。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-11-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-07-15
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多