Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot compile and link AVR program in OS X

I am working on a Mac with Yosemite OS X and I'm trying to compile a program in C that I could then upload onto my Arduino. I am following a tutorial.

I tried going through and reinstalling avr-gcc, but I got the same output. I tried searching for the file crtatmega328p.o on my system, but it is nowhere to be found and the same goes for the directory.

$ avr-gcc -Os -DF_CPU=16000000UL -mmcu=atmega328p -c -o Program.o Program.c
$ avr-gcc -mmcu=atmega328p Program.o -o Program
/usr/local/lib/gcc/avr/5.2.0/../../../../avr/bin/ld: cannot find crtatmega328p.o: No such file or directory

/usr/local/lib/gcc/avr/5.2.0/../../../../avr/bin/ld: cannot find -latmega328p
collect2: error: ld returned 1 exit status
like image 781
Brown Recluse Avatar asked Jul 31 '15 07:07

Brown Recluse


People also ask

What is AVR toolchain?

The AVR GCC Toolchain is a collection of tools and libraries used to compile your code for the AVR microcontrollers. This collection includes a compiler, assembler, linker, and some libraries.

Does Arduino use AVR GCC?

The Arduino IDE uses the avr-gcc compiler and avrdude to upload our program in the microcontroller.


1 Answers

I was just hit by this issue on GNU/Linux last week.

Actually, the compiler works fine. The cause of the issue is a failed linking attempt against avr-libc.

avr-libc-1.8.1 is simply too old to work with GCC 5. Although 1.8.1 is the latest version of avr-libc, but it was released one year ago... The developing version of avr-libc has updated to catch up GCC 5, you could clone the subversion repository:

svn co svn://svn.savannah.nongnu.org/avr-libc/trunk

and compile it by yourself. If you are not familiar about how to compile yourself home-made toolchains from the source code, there are plenty of documentation and tutorial on the web.

like image 137
比尔盖子 Avatar answered Sep 25 '22 01:09

比尔盖子