Monthly Archives: October 2014

gcc & g++ on an Arduino Yun

There is now a package available which will install GNU gcc on your yun, here is how I have it configured on my system. I was able to put together the openwrt package building on the work of dctsystems and some help from Federico Fissore. Sonnyyu has put out some great usage examples.

First to be sure I am starting with a clean slate I removed my microSD and flashed the latest Yun image (1.5.2) to my Yun using the Luci page at Backup Flash Firmware  with the keep settings box unchecked. This puts the Yun in a “factory” condition, so I needed to set my timezone and password and configure the Yun to connect to my WiFi network again. This step isn’t really necessary, I just did it to ensure I hadn’t forgotten anything needed to get gcc working.

Then I set my microSD up to be used as expanded disk space by the Yun. Follow the instructions here if you haven’t done this yet ExpandingYunDiskSpace. I used a 16gb UHS Class 1 microSD and set the data partition size to 11000MB which leaves just over 4GB for the system rootfs. The yun-gcc package definitely won’t fit in the space available unless you use a sd card, it doesn’t need to be 16GB, but they are cheap so I got a big one. Make sure you get a fast one, I tried some of this with an old Class 4 sd and it took over 3 times as long to accomplish things.

Next I installed some software we will want later. These commands in a ssh or terminal session will take care of this.

opkg update
opkg install binutils
opkg install make
opkg install tar

Now we are ready to install yun-gcc like this:

opkg -t /root install yun-gcc

This package will take about 20 minutes or more to install so be patient, once it finishes you will be ready to compile simple c or c++ programs. I prefer to download and install this package separately so I can see what is going on:

cd /mnt/sda1
opkg install yun-gcc_4.6.2-2_ar71xx.ipk

Most the examples sonnyyu gives in this forum thread should now work Example of Native GCC for Yun but with the ones that use a configure script, you should follow this first:

You need a real grep for many configure scripts to work, even the one that comes with grep (you need grep to compile grep???) the busybox version won’t suffice. You also need xz to uncompress the latest grep sources so here is how I dealt with it:

Download the grep sonnyyu provides a link to:

cd /mnt/sda1
wget -O grep_2.14-1_ar71xx.ipk --no-check-certificate
opkg install grep_2.14-1_ar71xx.ipk

This is enough to follow sonnyyu’s examples but I wanted to see if I could get the latest grep:

Download and compile xz:

cd /mnt/sda1
mkdir -p /usr/local/src
cd /usr/local/src
tar xvf xz-5.0.7.tar.bz2
cd xz-5.0.7
make install
cd ../

Traditionally, ./configure set things up to install in /usr/local so we need to add some things to our path:
export PATH=$PATH:/usr/local/bin:/usr/local/sbin

will add these to the current session, edit the fourth line in /etc/profile so they are available in future sessions:
[ -f /etc/banner ] && cat /etc/banner

export PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin
export HOME=$(grep -e “^${USER:-root}:” /etc/passwd | cut -d “:” -f 6)
export HOME=${HOME:-/root}
export PS1=’\u@\h:\w\$ ‘

[ -x /bin/more ] || alias more=less
[ -x /usr/bin/vim ] && alias vi=vim || alias vim=vi

[ -z “$KSH_VERSION” -o \! -s /etc/mkshrc ] || . /etc/mkshrc

[ -x /usr/bin/arp ] || arp() { cat /proc/net/arp; }
[ -x /usr/bin/ldd ] || ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; }

Now we can download and compile the latest grep:

tar xvf grep-2.20.tar.xz
cd grep-2.20
make install
cd ../

You can uninstall the grep that came in the ipkg so most things will use the busybox version as expected and configure scripts that need full grep should be smart enough to find the one in /usr/local/bin:
opkg remove grep

Go try all the examples in sonnyyu’s post to make sure everything is working. We are working with a 400 Mhz single core cpu with very limited resources so expect things to take a while compiling but they should eventually get there!