AVR Development in Eclipse IDE (Part 2)


I’ve been using Eclipse for a week or two now. I must say I do like the added features (I was using kate text editor and the command line before).

I’m using the subversion plugin for eclipse called Subversive. It makes everything quite a bit easier with point-and-click checkouts, commits, and updates. I also appreciate the ability to compare code in side-by-side windows. If working on larger projects with several developers the functionality that eclipse provides is invaluable.

Compiler Flags
I found there are a few compiler flags I’m used to that aren’t run by default in eclipse.

I discovered the first when I received an error while compiling:

error: ‘for’ loop initial declaration used outside C99 mode

This is due to variable declarations withing “for” statements:

for (unsigned char i=0; i<4; i++)

This isn’t allowed until the c99 standard, which the compiler doesn’t use by default, but must be told to do so.

The seconds problem I encountered was with the size of compiled HEX files. Using Eclipse to compile a program I was ending up with a hex file that was 9124 bytes. When compiled with a makefile I had been using previously I was getting a 6288 bytes in size. Obviously this size difference is a problem. With some help from curtvm over at avrfreaks.net I discovered that the math library was not being used by ecplipse when compiling.

Both of these issues are rather simple to fix. All we need to do is add the appropriate flags within the settings of eclipse.

  • Right-click on your project name and select Properties
  • Expand C/C++ build and click on Settings
  • Under AVR Compiler click on Miscellaneous
  • In the “other flags” box add “-std=gnu99”
  • Now at the left expand AVR C Linker and click on Libraries
  • In the box under “Libraries (-l) click the Add… button and put the letter “m” in (nothing else needed).
  • Click OK to finish up

That should pretty much fix things up. It worked for me!