Problem compiling 3pi demo programs with avr-gcc on Linux

I’ve successfully installed all the Linux AVR tools and I’ve had no problem downloading hex files to the 3pi. I was also able to install and build the pololu c/c++ library with no problem. However, when I try to compile any of the 3pi example programs they die with a string of error messages like these. Any suggestions?

[steevithak@triffid 3pi-demo-program]$ make
/usr/bin/avr-gcc -g -Wall -mcall-prologues -mmcu=atmega168 -Os   -c -o test.o test.c
test.c:77:2: error: invalid suffix "b00000" on integer constant
test.c:78:2: error: invalid suffix "b00000" on integer constant
test.c:79:2: error: invalid suffix "b00000" on integer constant
test.c:80:2: error: invalid suffix "b00000" on integer constant
test.c:81:2: error: invalid suffix "b00000" on integer constant
test.c:82:2: error: invalid suffix "b00000" on integer constant
test.c:83:2: error: invalid suffix "b00000" on integer constant
test.c:84:2: error: invalid suffix "b11111" on integer constant
test.c:85:2: error: invalid suffix "b11111" on integer constant
test.c:86:2: error: invalid suffix "b11111" on integer constant
test.c:87:2: error: invalid suffix "b11111" on integer constant
test.c:88:2: error: invalid suffix "b11111" on integer constant
test.c:89:2: error: invalid suffix "b11111" on integer constant
test.c:90:2: error: invalid suffix "b11111" on integer constant
test.c:95:2: error: invalid suffix "b00100" on integer constant
test.c:95: error: initializer element is not constant
test.c:95: error: (near initialization for 'note[0]')
test.c:96:2: error: invalid suffix "b00110" on integer constant
test.c:96: error: initializer element is not constant
test.c:96: error: (near initialization for 'note[1]')
test.c:97:2: error: invalid suffix "b00101" on integer constant
test.c:97: error: initializer element is not constant
test.c:97: error: (near initialization for 'note[2]')
test.c:98:2: error: invalid suffix "b00101" on integer constant
test.c:98: error: initializer element is not constant
test.c:98: error: (near initialization for 'note[3]')
test.c:99:2: error: invalid suffix "b00100" on integer constant
test.c:99: error: initializer element is not constant
test.c:99: error: (near initialization for 'note[4]')
test.c:100:2: error: invalid suffix "b11100" on integer constant
test.c:100: error: initializer element is not constant
test.c:100: error: (near initialization for 'note[5]')
test.c:101:2: error: invalid suffix "b11100" on integer constant
test.c:101: error: initializer element is not constant
test.c:101: error: (near initialization for 'note[6]')
test.c:102:2: error: invalid suffix "b00000" on integer constant
test.c:102: error: initializer element is not constant
test.c:102: error: (near initialization for 'note[7]')
test.c:107:2: error: invalid suffix "b00000" on integer constant
test.c:107: error: initializer element is not constant
test.c:107: error: (near initialization for 'back_arrow[0]')
test.c:108:2: error: invalid suffix "b00010" on integer constant
test.c:108: error: initializer element is not constant
test.c:108: error: (near initialization for 'back_arrow[1]')
test.c:109:2: error: invalid suffix "b00001" on integer constant
test.c:109: error: initializer element is not constant
test.c:109: error: (near initialization for 'back_arrow[2]')
test.c:110:2: error: invalid suffix "b00101" on integer constant
test.c:110: error: initializer element is not constant
test.c:110: error: (near initialization for 'back_arrow[3]')
test.c:111:2: error: invalid suffix "b01001" on integer constant
test.c:111: error: initializer element is not constant
test.c:111: error: (near initialization for 'back_arrow[4]')
test.c:112:2: error: invalid suffix "b11110" on integer constant
test.c:112: error: initializer element is not constant
test.c:112: error: (near initialization for 'back_arrow[5]')
test.c:113:2: error: invalid suffix "b01000" on integer constant
test.c:113: error: initializer element is not constant
test.c:113: error: (near initialization for 'back_arrow[6]')
test.c:114:2: error: invalid suffix "b00100" on integer constant
test.c:114: error: initializer element is not constant
test.c:114: error: (near initialization for 'back_arrow[7]')
make: *** [test.o] Error 1

After staring at the code for a few minutes, it suddenly hit me what the problem was. The code appears to be using things like “0b11111” as binary constants but this isn’t a standard C representation and isn’t supported by gcc. I googled a little and discovered some people apply a patch to avr-gcc to allow this syntax. In fact, it looks like the patch was accepted into the upstream gcc codebase. But’s in not in the avr-gcc 4.1.2 that ships with Redhat Fedora linux.

Anyway, it was easy enough to convert the constants to standard hex notation and the code is compiling fine now.

Oops, I had assumed that the 0b notation was standard enough to use everywhere. I guess I was wrong. Searching around on the web revealed a lot of interesting approaches to making something like a binary notation work in standard C or C++; the easiest seems to be to have an include file with

#define b00000 0
#define b00001 1
#define b00010 2
etc...

Maybe the next version of the example code will use something like that, instead. I hope that you aren’t also going to tell me that your version of avr-gcc doesn’t allow // comments or variable declarations in the middle of a block!

Thanks for figuring this out,
-Paul