Top Cat
Top Cat

Reputation: 351

"avr-gcc: command not found" on Ubuntu

I'm trying to work on an Arduino project from home. However, when I attempt to run the example code, I get the error:

avr-gcc: Command not found

This program runs fine on the university computers. However, isn't working at all on my Ubuntu virtual machine. I'm completely new to this. So, I honestly have no idea what's wrong.

Upvotes: 2

Views: 13828

Answers (3)

Sam_Carmichael
Sam_Carmichael

Reputation: 1

You probably need flex, byacc, bison, gcc, and libusb-dev:

sudo apt-get install flex byacc bison gcc libusb-dev

and libusb from libusb dot info, then use these commands in Terminal to install it from it's root installation directory:

./configure
make
sudo make install

or

sudo apt-get install libusb-1.0-0

Then download binutils: http://ftp.gnu.org/gnu/binutils/ configure it:

./configure --target=avr --program-prefix="avr-"

then make and install it. Afterward, download the latest version of GCC from: http://gcc.gnu.org/mirrors.html. It had errors after I tried to install it, saying I needed gmp, mpfr and mpc, so I downloaded them in this order from these websites:

https://gmplib.org/

https://www.mpfr.org/mpfr-current/

https://ftp.gnu.org/gnu/mpc/

and installed them using

./configure
make
sudo make install

in Ubuntu Terminal.

Luckily, after this, gcc installed successfully. Then you need to install avr-libc from: http://download.savannah.gnu.org/releases/avr-libc/

And avrdude to access the physical board: http://download.savannah.gnu.org/releases/avrdude/

Use

./configure --enable-linuxgpio 

on avrdude to enable general purpose input/output (and set the pins reset, sck, mosi, and miso in avrdude.conf). Avrdude checks (at the end) if you have libelf, libftdi1 , libftdi, and libhid

Download libelf from https://web.archive.org/web/20160430090619/http://www.mr511.de/software/libelf-0.8.3.tar.gz or

sudo apt-get update -y
sudo apt-get install -y libelf-dev

ftdi (for ftdi chips and ft chips which are usb to serial) which is optional, you can get it from intra2net or use these commands:

sudo apt-get update -y
sudo apt-get install -y libftdi1-dev
sudo apt-get install -y libftdi-dev

and finally libhid (human interface device):

sudo apt-get install libhidapi-dev

which it doesn't even detect for some strange reason.

You probably don't need to do all these steps. You could just try installing only avr for the minimum requirements but to be safe, it is recommended to go through the other steps.

When compiling an AVR program (compile the Arduino IDE libraries into a single library if you're using the IDE's code), you need to use g++, not gcc. This is some code and instructions to compile a simple program using Arduino:

//After calling it ardcpp.cpp, I compiled this and got it working for Arduino Uno (atmega328p) in Linux Terminal with the following 3 commands:
//avr-g++ ardcpp.cpp -O1 -Os -Wall -DF_CPU=16000000L -mmcu=atmega328p -I/snap/arduino/41/hardware/arduino/avr/cores/arduino -I/snap/arduino/41/hardware/tools/avr/avr/include/ -I/snap/arduino/41/hardware/arduino/avr/variants/circuitplay32u4 -I/usr/include/ -o ardcpp.bin
//avr-objcopy -j .text -j .data -O ihex ardcpp.bin ardcpp.hex
//avrdude -c arduino -P /dev/ttyUSB0 -p m328p -U flash:w:ardcpp.hex

#include <avr/io.h>
#include <util/delay.h>
//#include <Arduino.h>

int main (void) {
    DDRB |= _BV(DDB4);//data direction register sets 4th bit as output (pin 12)
    //0 thru 7 bits equal pins 8 thru 13, GND, and AREF on Arduino (SDA, and SCL for input from devices such as a gyroscope or a pressure/temperature/humidity sensor are not in PORTB, so use I2C/TWI for them)
    while(1) {
      //4=12,5=13
      PORTB |= (1<<4);//Set pin 12 to HIGH/ON
      _delay_ms(50);//wait 50 ms
      PORTB &= ~(1<<4);//Set pin 12 to LOW/OFF
      _delay_ms(50);//wait 50 ms
    }
}

'

Upvotes: 1

WesternGun
WesternGun

Reputation: 12797

What I tried was:

yum install *avr*gcc*

That found me some other longer packages with wildcards on my centos. I post this answer because this applies in many more cases and other dists.

Upvotes: 1

Chris
Chris

Reputation: 137139

avr-gcc: Command not found

This means precisely what it says: The avr-gcc command can't be found.

A search on avr-gcc quickly reveals the AVR Libc project:

AVR Libc is a Free Software project whose goal is to provide a high quality C library for use with GCC on Atmel AVR microcontrollers.

Together, avr-binutils, avr-gcc, and avr-libc form the heart of the Free Software toolchain for the Atmel AVR microcontrollers.

That sounds promising since Arduino uses Atmel CPUs.

Adding ubuntu to the search terms finds the gcc-avr package. Running sudo apt-get install gcc-avr on your VM should install the package.

Upvotes: 10

Related Questions