Go Down

Topic: Arduino0015+Eclipse problems (Read 5620 times) previous topic - next topic


Apr 27, 2009, 12:46 pm Last Edit: Apr 27, 2009, 02:07 pm by lz3060 Reason: 1
Hi Everyone,

I know compiling Arduino sketches with Eclipse is not supported, but still, I hope someone can give me a hand with this.

I was using Eclipse to write code for the Arduino and it worked beautifully with versions up to 0014. My setup follows the eclipse guide in the Playground, but with a few differences:

After creating my new project, I copy _all_ files from hardware/cores/arduino/ into an arduino/ folder inside the project, and I add that to the include directories for the C and C++ compilers. I do not use a pre-compiled core.a file, but link against .o files from the arduino folder. That allows me to modify the arduino lib when needed. I simply delete the main.cxx file and use my own:

Code: [Select]
#include "WProgram.h"

void setup(void);
void loop(void);

int main(void) {
     for (;;)

I have a separate file that defines my setup() and loop(), blink.cpp in this case:

Code: [Select]
#include "WProgram.h"

void setup(void) {
     pinMode(13, OUTPUT);

unsigned char state = HIGH;

void loop(void) {
     state = !state;
     digitalWrite(13, state);

This no longer works with the Arduino library from 0015 or SVN version.

This is the build log in eclipse, errors are highlighted at the end:


Compiling the blink example with the Arduino IDE with enabled verbose build:


As far as I can see, everything is about the same, with the only difference that I skip copying objects into the core.a file. I don't really understand all options passed to the compiler/linker. I'd be very happy if anyone can provide some insight.

I reviewed changes in the arduino library and noticed HardwareSerial.cpp does not rely on code in wiring_serial.c anymore. Deleting wiring_serial.c solves the duplicate interrupt handler issue, but the one for '__cxa_pure_virtual' remains. I suppose this is a problem of the compiler not being able to compile Print.cpp?!

Additional info about my setup:
OS: Ubuntu 9.04
avr-gcc 4.3.2
avr-libc 1.6.2 (both avr-gcc and avr-libc are the latest versions of the Ubuntu packages)

Eclipse: 3.4.1
AVR-Eclipse Plugin: 2.3.1

Arduino: Duemilanove with 328p

PS. This should probably be moved to 'Arduino Forum ? Software ? Troubleshooting'. Sorry, should have seen this category before posting.


After some more googling, it seems that the problem is a missing library, containing the '__cxa_pure_virtual' function.

But this method worked fine (and still does!) with the older arduino library.

I should probably modify the linker command, or add some objects to the linker configuration or .... anyone?


Did you try changing the last command from avr-gcc to avr-g++?  IIRC, __cxa_pure_virtual is something that should be generated by the C++ compiler.


Still the same error, even if linking with avr-g++:

Code: [Select]
Invoking: AVR C++ Linker
avr-g++ --cref -s -Os -o"ABox.elf"  ./blink.o ./main.o  ./arduino/HardwareSerial.o ./arduino/Print.o ./arduino/WInterrupts.o ./arduino/WMath.o ./arduino/pins_arduino.o ./arduino/wiring.o ./arduino/wiring_analog.o ./arduino/wiring_digital.o ./arduino/wiring_pulse.o ./arduino/wiring_shift.o    -lm -Wl,-Map,ABox.map,--cref -mmcu=atmega328p
./arduino/Print.o: In function `Print::write(char const*)':
../arduino/Print.cpp:32: undefined reference to `__cxa_pure_virtual'
make: *** [ABox.elf] Error 1

Also, here's the link command that the Arduino IDE issues:
Code: [Select]
avr-gcc -Os -Wl,--gc-sections -mmcu=atmega328p -o /tmp/build6378713336155302747.tmp/Blink.elf /tmp/build6378713336155302747.tmp/Temporary_7071_9587.cpp.o /tmp/build6378713336155302747.tmp/core.a -L/tmp/build6378713336155302747.tmp -lm

it also uses avr-gcc for linking, with slightly different options ...

Coding Badly

Apr 27, 2009, 08:30 pm Last Edit: Apr 28, 2009, 08:52 am by bcook Reason: 1
Are there duplicates of these files on your computer...


It appears the object files are place in very different places (with the source files versus in a temporary folder).  It is possible there is an errant object file tripping you up.

- Brian


I don't think that's it either :(. Still, I did a find / -name Print.o and found nothing suspicious.

Aren't all source object files listed on the command line?


I've been fighting with this for some days now. Alas, with no prior C/C++ experience I feel kind of lost.

If anyone is willing to try this out, here's an archive of the Eclipse project:


There is a Debug folder inside it, with automatically generated make files.

ABox/Debug $ make ABox.elf

should replicate the build process of Eclipse. Please try this out in your environment and let me know if you experience the same error.

Mellis, the build works if you replace the arduino folder with r577 from the google code svn repo. r578 introduces the virtual functions in Print.cpp, but I am wondering why does this work from the Arduino IDE, but not with this build process?!?

Thanks to everyone who took the time to read through this :)


I have not seen the files on the svn but as of 0015 Print::write(char const*) should be Print::write(uint8_t)


Actually, from Print.h

Code: [Select]
   virtual void write(uint8_t) = 0;
   virtual void write(const char *str);
   virtual void write(const uint8_t *buffer, size_t size);

The compile error is in Print.cpp, for this function:

Code: [Select]
/* default implementation: may be overridden */
void Print::write(const char *str)
 while (*str)

I found a few threads that suggest declaring&defining __cxa_pure_virtual() for pure virtuals to work. The big question for me now is _why_ does the arduino library compile with the Arduino IDE, but not with the Eclipse build?


Apr 28, 2009, 08:57 am Last Edit: Apr 28, 2009, 08:59 am by AlphaBeta Reason: 1
So they've added two write's then. Hmmm. For the ethernet maybe? [Or bufring generally?]

Just me guessing again:
Code: [Select]
/* default implementation: may be overridden */
void Print::write(const char *str)
 while (*str)

But it is very strange that it compiles with Arduino IDE and not eclipse.


Nope, that didn't work either.

I am now able to compile the sketch with Eclipse if I add

Code: [Select]
extern "C" void __cxa_pure_virtual(void);
void __cxa_pure_virtual(void) {}

in any .cpp file. Without it, it always complains with

Code: [Select]
./arduino/Print.o: In function `Print::write(char const*)':
../arduino/Print.cpp:32: undefined reference to `__cxa_pure_virtual'

Can you guys download the code and try running the build?

Also, does anyone know where to get a full list of avr-gcc options and their meanings? I can't find a man page, avr-gcc -v --help doesn't seem to list everything ...



Indeed. However, it seems to me the problem is with the Arduino library, and the question is why does your build work.

Someone at AVRFreaks has written a tutorial on coding C++ for the AVR. Part of what needs to be done is definition and implementation of a void __cxa_pure_virtual(void) function. There is no such function in the Arduino library, hence the build error.

However, when building the project with an object archive (not sure about the terminology here), it magically works! The Arduino IDE copies all C and C++ compiled object files into core.a, and then links the main object file against it (and any other libraries outside the core). This I cannot explain.

Can someone shed some light on this?

Coding Badly

One thing looks suspicious.  I think this is the link step...

Code: [Select]

avr-gcc --cref -s -Os -o"ABox.elf"  
-lm -Wl,-Map,ABox.map,--cref -mmcu=atmega328p

I think one or more crt*.o files need to be included in that step.  That may be where the elusive __cxa_pure_virtual has gone.

Good luck,


Hmm. Where are these crt*.o files supposed to come from? The official IDE does not use any ...

I am still digging into this out of pure curiosity. I want to know why the Arduino IDE build works, while it shouldn't?!

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131