Orangutan X2 in c++ not c Atmel Studio 6.2

I have been trying to program my Orangutan X2 in C++ using the Pololu templates for Atmel Studio 6.2. What do I have to do to get my main.c to work with c++? I have tried creating a class either in an external file or in the main.c file and I get the following error:
“unknown type name ‘class’”

So, thinking this was an issue with it being a .c file instead of a .cpp file, I renamed main.c, to main.cpp changed the includes to c++ style and tried again, at that point I get:
“undefined reference to ‘main’”

Finally, I created a new project deleted main.c and created main.cpp, attempted to compile and I still get:
“undefined reference to ‘main’”

The templates included with the Pololu AVR Development Bundle say C/C++, but how can I program in C++ with them?


To program your Orangutan in C++, you will need to create a new template and configure some settings in Atmel Studio. You can follow the steps in this thread where one of our forum members posed a similar question.

- Amanda

Ok, so I was finally able to get this working. Unfortunately, some of the settings seem to differ for the X2 from what was in the thread about the 3pi.
For anyone else needing to do this on an X2, I will include the differences:
You have to define a symbol under the AVR/GNU C++ Compiler Symbols section with the value _X2_1284
Also, enabling the compiler optimization -ffunction-sections seems to cause any const or static unsigned int values declared outside the main loop to be initialized improperly, so I had to remove that optimization for the X2. For more info on that see my post at Stack Overflow: stackoverflow.com/questions/2938 … 5_29382707

At this point all seems to be working well. I was actually most of the way there, when I posted this, but ffunctions-sections and fdata-sections were causing issues with the values of my static const unsigned int and static const unsigned char values.

It would also be super helpful if the templates Pololu provides didn’t say C/C++ when they don’t work with C++.

An update on the “Using the Pololu AVR Library for your own projects” part of the “Pololu AVR C/C++ Library User’s Guide” to work with Atmel Studio 6 would have solved this without a forum post. The interface has changed so much since 4 that it’s really difficult to translate the instructions for 4 to 6.

I am glad you were able to get it working; thanks for letting us know the adjustments you had to make.

- Amanda