Happy Birthday, GCC!! 4.7.0 Released

Happy Birthday!

photo by Mike Rampton

After 25 years, GCC has released the best toolset to date, 4.7.0. I’ve been running SVN snapshots for a few months now, and I’ve found it to be excellent. The most important innovation is Named Address Spaces, making it much easier to handle data whether it resides in flash or SRAM. It also fixes many annoying bugs, generates the smallest code to date, and implements many time-saving c++11 features.

In this post, I’ll walk through how I installed it on Ubuntu 11.10, as many people have asked for details on how to set it up. To check this, I did a fresh install on a virgin machine, and simply wrote down everything I did.

For my friends running Windows, you can just check out Sprinter SB’s Windows Packages.

Background Reading

First, there are a few things to read:


We’ll be compiling and installing 3 packages from source:


GCC itself needs a few pre-requisites

$ sudo apt-get install libgmp3-dev libmpfr-dev libmpc-dev


Get the packages.

$ cd ~/Downloads
$ wget ftp://ftp.gnu.org/gnu/binutils/binutils-2.22.tar.bz2
$ wget ftp://ftp.gnu.org/gnu/gcc/gcc-4.7.0/gcc-4.7.0.tar.bz2
$ wget http://download.savannah.gnu.org/releases/avr-libc/avr-libc-1.8.0.tar.bz2


$ cd ~/Source/avrtools
$ tar xvfj ~/Downloads/binutils-2.22.tar.bz2
$ cd binutils-2.22
$ mkdir obj-avr
$ cd obj-avr
$ ../configure --prefix=/usr/local/avr --target=avr --disable-nls
$ time make -j4
real 1m35.153s
user 3m49.562s
sys 0m35.486s
$ sudo make install

Many references on the web include “–enable-isntall-libbfd”, although the official instructions do not. I couldn’t find a good reason either way to include it or remove it, so I’ve left it off. Everything seems to work fine without it.

I like to put the tools in /usr/local/avr, to separate them from the default location of /usr/local. This makes it easy to wipe out the entire tools with one simple ‘rmdir’ if things to wrong.

Also, we need to make sure this is on our path now:

$ export PATH=/usr/local/avr/bin:$PATH


When it comes to where we should build the gcc objects, the avr-gcc instructions and official gcc instructions diverge. I’ve had problems with the object directory under the source directory, and the official instructions say this is not supported. So we build them in separate locations.

$ cd ~/Source/avrtools
$ tar xvfj ~/Downloads/gcc-4.7.0.tar.bz2
$ mkdir gcc-4.7.0-obj-avr
$ cd gcc-4.7.0-obj-avr
$ ../gcc-4.7.0/configure --prefix=/usr/local/avr --target=avr --enable-languages=c,c++ --disable-nls --disable-libssp
$ time make -j4
real 10m49.563s
user 22m59.898s
sys 3m30.461s
$ sudo make install

Make sure everything is installed so-far correctly:

$ avr-gcc -v
Using built-in specs.
Target: avr
Configured with: ../gcc-4.7.0/configure --prefix=/usr/local/avr --target=avr --enable-languages=c,c++ --disable-nls --disable-ibssp
Thread model: single
gcc version 4.7.0 (GCC)


Avr-libc is happy to have the objects built right in the source directory, so no need to create the separate objects directory.

$ cd ~/Source/avrtools
$ tar xvfj ~/Downloads/avr-libc-1.8.0.tar.bz2
$ cd avr-libc-1.8.0
$ ./configure --prefix=/usr/local/avr --build=`./config.guess` --host=avr
$ time make -j4
real 1m21.448s
user 1m38.502s
sys 1m20.129s
$ sudo make install


Grab some quick simple examples to test it out on:

$ cd ~/Source/avrtools
$ wget -O - http://www.tuxgraphics.org/common/src2/article09043/avrledtest_timer-0.2.tar.gz | tar xvz
$ cd avrledtest_timer-0.2
$ make
avr-gcc -g -mmcu=atmega8 -Wall -Wstrict-prototypes -Os -mcall-prologues -Os -c ledtimer.c
avr-gcc -g -mmcu=atmega8 -Wall -Wstrict-prototypes -Os -mcall-prologues -o ledtimer.out -Wl,-Map,ledtimer.map ledtimer.o
avr-size ledtimer.out
text data bss dec hex filename
168 0 1 169 a9 ledtimer.out
avr-objcopy -R .eeprom -O ihex ledtimer.out ledtimer.hex


Filed under Uncategorized

6 responses to “Happy Birthday, GCC!! 4.7.0 Released

  1. Diecore

    Do you have any idea why the gcc for AVR32 UC3 microcontrollers is so (ver 4.4.3) old?

  2. Joe

    Know when they are going to support xmega32a4U?

  3. uzi18

    Is it possible for You to test this release in comparision to older gcc?
    Please also explain new features if it is possible🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s