Setup of AVR cross-compiler in Ubuntu /Linux mint /Fedora

Keywords: AVR, atmega32, avr-gcc, avrdude , installation of avr-gcc

Installation of avr-gcc in Linux is the first post in the Embedded section of Techawarey. Soon you will find a complete tutorial series on development with AVR micro-controller (specifically Atmega32) that will cover introduction of AVR, interfaces in AVR , programming example etc.

Atmega32 AVR micro controller is one of the common and favorite micro-controller among hobbits and new learners.

The architecture of the AVR or other target micro-controller is different from the MCU of your PC/Laptop. Therefor when you write a code and compile it on your PC, it can not work on your target micro-controller. You will require a special compiler (cross-compiler) to compile your code according to your micro-controller. For Windows and Linux there are some ready to use cross-compiler available already, but here I’ll explain how to make a cross compiler from scrach. It’s not easy but also not too much difficult if you like to face challenges.. 😉

Ok.. Enough talk… let’s start..

Please note that all the steps given below are tested on Ubuntu 10.04- Ubuntu-12.10 and Fedora. These should work with Linux mint and other Debian based Linux distribution as well.

To build cross-compiler for AVR, you will require following packages. Version of packages mentioned here are tested and working together. Go to respective sides and download all the packages.

Step : 1 Download following packages:

1. binutils-2.19

2. gcc-4.3.2

3. avr-libc-1.6.4

 4. avrdude-5.5

Step : 2 Create two directories in your home directory:

(a) avrcross

(b) avr

Step : 3 Copy above downloaded packages in ‘avrcross’ directory.

Note that we’ll compile the packages in avrcross directory and install them in ‘avr’ directory. So this will be ‘prefix’ for command arguments. Also after installing them in this location you have to add PATH of ‘/home/<user_name>avr/bin’ in search path of your Linux distribution.

Step -4 Besides a C-compiler with gmake and basic unix commands you need also: texinfo, bison, flex, gawk, readline and ncurses. If your system does not have installed them already , then install them first using ‘apt-get install ‘ command:

ex: sudo apt-get install texinfo

sudo apt-get install flex etc

Step : 5 You should switch now to bash unless you use bash already as your default shell. Type:


Step : 6 Open a terminal and and enter to ‘avrcross’ directory by ‘cd avrcross’. And then issue following commands :


Installation of binutils-2.19

Step : 6 (a) tar jxvf binutils-2.19.tar.bz2


Output will be look like below screen-shots.



Step : 6 (b) cd binutils-2.19


Step : 6 (c) mkdir obj-avr


Step : 6 (d) cd obj-avr


Step : 6 (e) CC=gcc


Step : 6 (f) export CC

Step : 6 (g) ../configure –target=avr –prefix=/home/mysys/avr –disable-nls –enable-install-libbfd


If no error then you should see output like this:


Step : 6 (h) make


If no error you should see output like given screen shots:



Step : 6 (i) make install

You will see the below output if there is no error.


Step : 6 (j) cd ../..


Installation of gcc-4.2.3

Step : 7 (a) tar jxvf gcc-core-4.2.3.tar.bz2


Step : 7 (b) cd gcc-4.3.2


Step : 7 (c) mkdir obj-avr

Step : 7 (d) cd obj-avr


Step : 7 (e) ../configure –target=avr –prefix=/home/mysys/avr –disable-nls –enable-languages=c –disable-libssp


If no error then you will see output like this:


Step : 7 (f) make

If no error then you will see below output:


Step : 7 (g) make install

If no error then you will see below output:


Note: The above step requires a recent version of MPFR ( and gmp ( GMP 4.1+ and MPFR 2.3.0+. Use the packages from your distribution if possible. Under Ubuntu those packages are called libgmp3-dev and libmpfr-dev. Gentoo calls them dev-libs/gmp and dev-libs/mpfr. So if you see error like this then you have to install these packages as well. Follow the below steps if you get the error like below screen shots:


Step : 7 (h) sudo apt-get install libgmp3-dev


Step : 7 (i) sudo apt-get install libmpfr-dev


Step : 7 (j) make clean

Step : 7 (k) make

Step : 7 (l) make install

Step : 7 (h) cd ../..

Installation of avr-libc-1.6.4

Step : 8 (a) tar jxvf avr-libc-1.6.4.tar.bz2


Step : 8 (b) cd avr-libc-1.6.4

Step : 8 (c) PREFIX=/home/mysys/avr

Step : 8 (d) export PREFIX

Step : 8 (e) CC=avr-gcc

Step : 8 (f) export CC


Step : 8 (g) PATH=/home/mysys/avr/bin:${PATH}

Step : 8 (h) export PATH


Step : 8 (i) ./configure –build=./config.guess –host=avr –prefix=/home/mysys/avr


Step : 8 (j) make

If no error then you will see output like this:


Step : 8 (k) make install


Step : 8 (l) cd ..

Installation of avrdude-5.5

Step : 9 (a) tar zxvf avrdude-5.5.tar.gz


Step : 9 (b) cd avrdude-5.5/

Step : 9 (c) CC=gcc

Step : 9 (d) export CC

Step : 9 (e) ./configure –prefix=/home/mysys/avr


Step : 9 (f) make


Step : 9 (g) make install

If no error then you will get output like below screen shot:


Now the installation is complete. The package ‘avrdude‘ is the utility to program the AVR micro-controller. You are ready to compile the codes for AVR micro-controller and program the chip using ‘avrdude‘.

Note: if you don’t want to follow above steps and make it done in quickest way then execute following command in terminal:

# sudo apt-get install make avr-libc avrdude binutils-avr gcc-avr gdb-avr

You can build your own programmer that work with avrdude or you can buy it from here at a cheap cost. In up-coming posts you will see how to write the codes and compile them.

Above setup will work with Atmel atmega32, atmega168, amtmega328 and many more.

If you like the post useful then please like and share it. Also don’t forget to like the facebook page of Techawarey. 🙂 🙂

Related posts

2 Thoughts to “Setup of AVR cross-compiler in Ubuntu /Linux mint /Fedora”

  1. […] Setup of AVR cross-compiler in Ubuntu /Linux mint /Fedora […]

  2. Anonymous

    Wow mast hai bhai…………….maine bhi kiya….

Leave a comment....