This is a quick primer on using Eclipse, AVR, and MacOS. A detailed guide is provided on the Arduino website, but I’ve documented the particularities of MacOS here.

Before you begin, download the following software:

Instructions

  1. Install GCC, Eclipse, and the AVR tool suite
  2. Test GCC and AVR Tool Suite
    1. Open terminal
    2. Type “gcc –version”
    3. Type “avr-gcc –version”
    4. You should see something like this:

Command Line Test

  1. Launch Eclipse and ensure you have the C/C++ perspective.
    1. Look at top right hand of screen – you should see:
    2. C/C++ Perspective

    3. If not, click the square icon with the gold plus in the upper right hand corner to change perspectives.
    4. Select Other…
    5. Select “C/C++“.
    6. Select C/C++ Perspective

    7. If you don’t have the C/C++ perspective, add the perspective via the Eclipse download manager
      1. Click on “Help->Install New Software…
      2. Install New Software

      3. Select Helios in the drop down labeled “Work with:”
      4. Install Location

      5. Click the arrow next to “Programming Languages”
      6. Check “C/C++ Development Tools
      7. Install C/C++ Perspective

      8. Click Next, Next, I Accept, and Finish
      9. Wait for the install and click “Restart”
  2. Quit Eclipse

<<This is where we deviate from the install instructions on the Eclipse AVR Plugin website.  I’m still working on getting v2.3.4 working on the Mac>>

  1. Unzip the Eclipse AVR Plugin
  2. Plugin Unzipped

  3. Copy the contents of “features” to the “features” directory of your Eclipse install
  4. Eclipse Directory

  5. Copy the contents of “plugins” to the “plugins” directory or your Eclipse install
  6. Start Eclipse
  7. You should see the “AVR” icon next to the build icon.
  8. AVR Plugin

Now, adjust avrdude settings in Eclipse by using latest processor, port, and baud rate:

  1. avrdude -pm328p -cstk500 -P/dev/tty.usbserial-A600aftj -b57600 -t

avrdude Setup

For each of your “main” files, you need to have the following “method” to ensure linking with the C++ libraries work properly:

extern "C" void __cxa_pure_virtual()<br />{<br />  while (1);<br />}<br />

Now you can configure your first project according to the instructions on the Arduino website.

One point to note – ensure you set up the linker properly.  I struggled for 2 days trying to get my program to link properly.  It suddenly started working and I really have no clue what I changed to make it work.  One of last things I set was the linker command line and the optimizations, so perhaps that was it.

-ffunction-sections -fdata-sections -Wl,--gc-sections

Note – Adding the above to the optimizations seems to make the generated files larger, but the resulting hex file seems to be the same size with and without the flag.

Optimizations

${COMMAND} --cref -s -Os ${OUTPUT_FLAG}${OUTPUT_PREFIX}${OUTPUT} ${INPUTS} -lm ${FLAGS}

Linker Command Line

One final and very important suggestion. Once you get a project working properly, always copy that project as a starting point. It’s a lot easier than trying to recreate all the steps necessary to get all of this working.

That should be it.

Other Links

  1. Lady Ada Mac Setup – http://www.ladyada.net/library/avrdevtut/setup-mac.html
  2. http://homepage.mac.com/chen/w7ay/AVR%20Tools/Contents/resources.html
  3. Windows-based, but a good reference: http://robertcarlsen.net/2009/10/31/arduino-in-eclipse-989