3. Compiling avr-gcc

The latest versions of GCC (4.2.3 and up) include support for the ATmega328P, as well as the ATmega48P, ATmega88P, and ATmega168P.

Checking the currently installed version of avr-gcc

Run the following command:

avr-gcc --version

You can test for support by creating an empty file test.c and running avr-gcc -mmcu=atmega328p test.c. If your version of gcc does not support the chip, you will see the following errors:

unknown MCU 'atmega328p' specified
...
test.c:1: error: MCU "atmega328p" supported for assembler only

Installing prerequisites

Recent versions of GCC (4.3.x) depend on GMP and MPFR, which can be installed from their web pages. Under Ubuntu, you can get these packages by running the following command.

sudo apt-get install libgmp3-dev libmpfr-dev

Other distributions probably provide similar packages.

Downloading the source code

Get gcc-4.3.3.tar.bz2 or a later version from the GCC FTP site or from a mirror closer to you if possible. We recommend getting the full GCC, which includes the C++ compiler, not just gcc-core.

Unpack the archive

Run the following command:

tar xjf ~/Desktop/gcc-4.3.3.tar.bz2
cd gcc-4.3.3

Configure, compile, and install GCC

Note that you need to compile GCC from a separate directory, and that we are specifying that only C and C++ be included. If you want to try compiling FORTRAN, ObjectiveC, or GCJ for the AVR, you’re on your own!

mkdir build
cd build
../configure --prefix=/usr/local --target=avr --enable-languages=c,c++ --disable-nls --disable-libssp
make
sudo make install

Next steps

The latest version of avr-gcc should now be on your path. Next, proceed to Section 4 to install avr-libc for all of the AVR microcontrollers supported by GCC.

New Products

Pololu I²C Isolator with Isolated Power and Connectors, ISO1640, MIE1W0505BGLVH, 5V/3.3V, 200mA
Glideforce GF01-122110-1-66 Micro Linear Actuator with Limit Switches: 12V, 8.1kgf, 6mm/s, 100mm Stroke
ACS37041KLHBLT-010B5 Current Sensor Micro Carrier -10A to +10A, 5V
Pololu RC Switch with Isolated Solid State Relay/Switch, SPST, 30V, 10A (Soldered Connectors)
JST SH-Style Connector Board for Micro Metal Gearmotors, 2-Pin, Back-Entry (2-Pack)
JST PH-Style Cable with Female Pins for 0.1" Housings, 4-Pin, 12cm
APM81815 Step-Down Voltage Regulator Carrier, 5.35V Out
JST SH-Style Cable, 4-Pin, Single-Ended Female, 30cm
ACS37042KLHBLT-030B5 Current Sensor Compact Carrier -30A to +30A, 5V
ACS37042KLHBLT-010B5 Current Sensor Compact Carrier -10A to +10A, 5V
Log In
Pololu Robotics & Electronics
Shopping cart
(702) 262-6648
Same-day shipping, worldwide
Menu
Shop Blog Forum Support
My account Comments or questions? About Pololu Contact Ordering information Distributors