error compiling on gcc-avr 4.6.1

I upgraded gcc-avr (avr-gcc) from 4.6.0 to 4.6.1 and now I get this error when I click "Compile" button ("play" button) even on empty sketch!

In file included from /usr/share/arduino/hardware/arduino/cores/arduino/Tone.cpp:37:0:
/usr/share/arduino/hardware/arduino/cores/arduino/pins_arduino.h:66:48: error: variable 'port_to_mode_PGM' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
/usr/share/arduino/hardware/arduino/cores/arduino/pins_arduino.h:67:49: error: variable 'port_to_input_PGM' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
/usr/share/arduino/hardware/arduino/cores/arduino/pins_arduino.h:68:50: error: variable 'port_to_output_PGM' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
/usr/share/arduino/hardware/arduino/cores/arduino/pins_arduino.h:70:54: error: variable 'digital_pin_to_port_PGM' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
/usr/share/arduino/hardware/arduino/cores/arduino/pins_arduino.h:72:58: error: variable 'digital_pin_to_bit_mask_PGM' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
/usr/share/arduino/hardware/arduino/cores/arduino/pins_arduino.h:73:55: error: variable 'digital_pin_to_timer_PGM' must be const in order to be put into read-only section by means of '__attribute__((progmem))'
/usr/share/arduino/hardware/arduino/cores/arduino/Tone.cpp:108:45: error: variable 'tone_pin_to_timer_PGM' must be const in order to be put into read-only section by means of '__attribute__((progmem))'

on gcc-avr 4.6.0 clicking the same button gives "... done" but 4.6.1 gives the above error.
I posted the bug to gcc-avr but they say the bug is in arduino ide and not in gcc...
could you atleast tell me the command line to compile a arduino uno code from the console (terminal, cmd). So I can post the exact command line that gives that error in gcc bugzilla.
I tried to compile a C code with avr-gcc 1.c -o 1 and it compiled without any errors. But compiling in IDE gives that error. So I don't know how to identify the bug'er.

p.s. my board is Arduino Uno (ATmega328P-PU), OS is ArchLinux x86_64, gcc & gcc-avr are 4.6.1

[_artem_@linux-void ~]$ avr-gcc -v
Using built-in specs.
COLLECT_GCC=avr-gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/avr/4.6.1/lto-wrapper
Target: avr
Configured with: ../configure --disable-libssp --disable-nls --enable-languages=c,c++ --infodir=/usr/share/info --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --prefix=/usr --target=avr --with-gnu-as --with-gnu-ld --with-as=/usr/bin/avr-as --with-ld=/usr/bin/avr-ld
Thread model: single
gcc version 4.6.1 (GCC) 
[_artem_@linux-void ~]$

Press Shift while clicking compile to see the command lines generated to compile your sketch.

The error looks like it is to do with const correctness - maybe the new GCC has changed how it deals with progmem data. I'd say the gcc-avr people are probably right, the bug might be with the Arduino headers not being properly const correct.

What version of the arduino ide do you have? I see it is installed system wide. Maybe you use outdated code.

V 0022 has this:

pins_arduino.c

const uint16_t PROGMEM port_to_mode_PGM[]

thanks for "Shift+" :slight_smile:

avr-g++ -c -g -Os -w -fno-exceptions -ffunction-sections -fdata-sections -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=22 -I/usr/share/arduino/hardware/arduino/cores/arduino /usr/share/arduino/hardware/arduino/cores/arduino/Tone.cpp -o/tmp/build941971144755971461.tmp/Tone.cpp.o

so this code gives such an error...

Error is produced by this lines from the pins_arduino.h

extern const uint16_t PROGMEM port_to_mode_PGM[];
extern const uint16_t PROGMEM port_to_input_PGM[];
extern const uint16_t PROGMEM port_to_output_PGM[];

extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
// extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];

I'm using 0022, installed in archlinux from aur. Just downloaded the latest package from arduino.cc, extracted, changed path in the command line to not to use my system-wide headers. It gives the same error.

@artem I'm on your same boat.. same problem here.

I've temporarily fixed the problem by downgrading to gcc-avr 4.6.0-3. I found that I had the older version 4.6.0-3 in /var/cache/pacman/pkg ..
A simple pacman -U /var/cache/pacman/pkg/gcc-avr-4.6.1-1-x86_64.pkg.tar.xz fixed the issue.

yes on 4.6.0-3 code compiles just fine, but delay() doesn't work. So I'm still hoping that delay() function was fixed in 4.6.1 but I can't try it because either avr-g++ or ide is buggy

The delay() bug has been solved before, search for it. It was a problem with avr-binutils, not avr-gcc, so even if gcc 4.6.1 worked you would still get the bug. It is solved by patching the binutils sources with a Debian patchset before compiling (this is something the arch avr-binutils package maintainers should do)

I can confirm the same problem. Also running arch.

pacman -U /var/cache/pacman/pkg/gcc-avr-4.6.1-1-x86_64.pkg.tar.xz

works great thanks Fabio.

here ya go artem:

http://arduino.cc/forum/index.php/topic,49900.15.html

The reason I posted it for you rather than having you find it yourself is because when I had that problem I remember having a hard time wording the search correctly.

Hi, guys

I've managed to compile and run blink example for Arduino Uno on archlinux x86_64, gcc-avr 4.6.1

Here is patch:

diff -u /usr/share/arduino/hardware/arduino/cores/arduino/pins_arduino.h ./pins_arduino.h
--- /usr/share/arduino/hardware/arduino/cores/arduino/pins_arduino.h	2011-07-19 14:29:17.000000000 +0300
+++ ./pins_arduino.h	2011-07-19 09:47:42.732685122 +0300
@@ -63,14 +63,14 @@

 // On the ATmega1280, the addresses of some of the port registers are
 // greater than 255, so we can't store them in uint8_t's.
-extern const uint16_t PROGMEM port_to_mode_PGM[];
-extern const uint16_t PROGMEM port_to_input_PGM[];
-extern const uint16_t PROGMEM port_to_output_PGM[];
+extern const prog_uint16_t port_to_mode_PGM[];
+extern const prog_uint16_t port_to_input_PGM[];
+extern const prog_uint16_t port_to_output_PGM[];

-extern const uint8_t PROGMEM digital_pin_to_port_PGM[];
-// extern const uint8_t PROGMEM digital_pin_to_bit_PGM[];
-extern const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[];
-extern const uint8_t PROGMEM digital_pin_to_timer_PGM[];
+extern const prog_uint8_t digital_pin_to_port_PGM[];
+// extern const prog_uint8_t digital_pin_to_bit_PGM[];
+extern const prog_uint8_t digital_pin_to_bit_mask_PGM[];
+extern const prog_uint8_t digital_pin_to_timer_PGM[];

 // Get the bit location within the hardware port of the given virtual pin.
 // This comes from the pins_*.c file for the active board configuration.
diff -u /usr/share/arduino/hardware/arduino/cores/arduino/Tone.cpp ./Tone.cpp
--- /usr/share/arduino/hardware/arduino/cores/arduino/Tone.cpp	2011-07-19 14:29:17.000000000 +0300
+++ ./Tone.cpp	2011-07-19 14:28:34.798922373 +0300
@@ -90,7 +90,7 @@
 
 #define AVAILABLE_TONE_PINS 1
 
-const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 3, 4, 5, 1, 0 */ };
+const prog_uint8_t tone_pin_to_timer_PGM[] = { 2 /*, 3, 4, 5, 1, 0 */ };
 static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255, 255, 255, 255, 255 */ };
 
 #elif defined(__AVR_ATmega8__)
@@ -105,7 +105,7 @@
 #define AVAILABLE_TONE_PINS 1

 // Leave timer 0 to last.
-const uint8_t PROGMEM tone_pin_to_timer_PGM[] = { 2 /*, 1, 0 */ };
+const prog_uint16_t tone_pin_to_timer_PGM[] = { 2 /*, 1, 0 */ };
 static uint8_t tone_pins[AVAILABLE_TONE_PINS] = { 255 /*, 255, 255 */ };

 #endif

Apply it with

cd / && sudo patch -p0 < /tmp/arduino.patch

As you see, I changed only types for constants. Got working ones from "avr/pgmspace.h", like:

typedef uint16_t PROGMEM prog_uint16_t;

So, it seems to me, that the problem lies in gcc-avr.

P.S.: delay() issue still exists with gcc-avr 4.6.1

This solution works only on arch linux and derivate. Corrected commands are:
32bit pacman -U /var/cache/pacman/pkg/gcc-avr-4.6.0-3-i686.pkg.tar.xz
64bit pacman -U /var/cache/pacman/pkg/gcc-avr-4.6.0-3-x86_64.pkg.tar.xz

you can also blacklist gcc-avr in /etc/pacman.conf

Thanks @ygrek .. your patch seems to be working without any side effects also on more complex Arduino sketches. I can now use the newer gcc-avr without problems.

A bug report against gcc-avr has been opened by artem at 49764 – [avr-g++] Rejects attribute progmem

Sorry i receive an error:
pacman -U /var/cache/pacman/pkg/gcc-avr-4.6.0-3-i686.pkg.tar.xz

error: '/var/cache/pacman/pkg/gcc-avr-4.6.0-3-i686.pkg.tar.xz': cannot open package file

Can you help me?

simply write "/var/cache/pacman/pkg/gcc-avr-4"
the hit 1 or 2 times TAB, it will show you all disponible file in the directory that begin with this name. pick up the most recent. If nothing apper, i think is because you have deleted them. If this is the case, look if someone is kind wnought to post you the package (I've deleted theb because of some problem with HD space :D)

This is only version :

$ cd /var/cache/pacman/pkg/gcc-avr-4.6.1-1-i686.pkg.tar.xz

My problem in not compile ,but use DELAY();
Can you help with this please?
Thanks a lot

For those of you who don't have the gcc-avr-4.6.0-3 package anymore, you still can download it here :

http://schlunix.org/archlinux/pool/community/gcc-avr-4.6.0-3-i686.pkg.tar.xz
or
http://schlunix.org/archlinux/pool/community/gcc-avr-4.6.0-3-x86_64.pkg.tar.xz

And thanks for your patch, ygrek. It seems to work fine :wink:

Just want to let you know that using the following command in fedora15 i was able to get the Arduino IDE to compile again.

sudo yum downgrade avr-gcc avr-gcc-c++

Hi,

had the same issue here with gcc-avr-4.6.1 on Arch Linux. But today I could update to gcc-avr-4.6.2-1; and that solved it.

I have same problem!

const char	num1[] PROGMEM = "09194986646", num2[] PROGMEM = "66737819";
char* num[]  PROGMEM = {(void *)num1, (void *)num2};

It works fine when compiling with WINAVR2010 but compiling

const char	num1[] PROGMEM = "09194986646", num2[] PROGMEM = "66737819";
PGM_P num[]  PROGMEM = {(void *)num1, (void *)num2};

with gcc version 4.6.2 (AVR_8_bit_GNU_Toolchain_3.4.1_798) the compiler returns this error:

monitoring.c:10:7: error: variable 'num' must be const in order to be put into read-only section by means of '__attribute__((progmem))'

Have anybody solved this ptoblem?

Two years ago, and I have same problem:
Using older versions of Arduino IDE is OK, but latest betas 1.5.6 , 1.5.7 and 1.5.8 produces same error:

error: variable Text'Info' must be const in order to be put into read-only section by means of 'attribute((progmem))'

My program contains:
char TextInfo [] PROGMEM = "some text";

Changing to
const TextInfo [] PROGMEM = "some text";

causes another error:
error: 'TextInfo' does not name a type

Please, I am beginner and I do not uderstand all of C++ nuances, can you help me to solve this problem?