arduino library with eclipse

Hey All,

I want to use eclipse and the arduino libraries to program some atmega168 chips without any arduino hardware. I just want to make use of the wicked arduino libraries. I have gone through the tutorial here:
and everything seems to be working fine. I’m using the stk500 as a programmer. I have successfully compiled and programmed a chip with a simple blink program. The problem is now I want to use other parts of the library (hardware serial) but I just get errors that seem to be related to not having the libraries setup correctly.
If I try “Serial.begin(19200);” I get:
error: ‘Serial’ undeclared (first use in this function)

Any advice about how to get these libraries working with Eclipse would be greatly appreciated.


I haven't used Eclipse, so I don't know it's special handing, but in general to use the HardwareSerial library, you have to add "HardwareSerial.cpp" to your project, so it gets compiled and linked. "Serial" is defined there at the very end of "HardwareSerial.cpp".

In your own cpp files you have to include the header "HardwareSerial.h" to make use of the "extern HardwareSerial Serial" declaration.


I am struggling with this as well. I have HardwareSerial.h included but is doesn't make any difference. Does anybody have this fixed yet?

Have you included the library path(s) in the eclipse set up?

Project Properties (right click on project name->Properties) AVR Compiler->Directories AVR C++ Compiler->Directories AVR C++ Linker->Libraries (the name of the library w/o 'lib') AVR C++ Linker->Libraries Path (the path to the library)

I like that Arduino hides all the details of compilation from you, but it certainly makes it difficult when you want more from a editor than the arduino tool can offer.

This is a compiler problem. I think you are using the avr-gcc as your AVR Compiler when you really should be using avr-g++. "Serial." is a C++ header, so you need to be using avr-g++. By using avr-gcc, you are trying to compile it as C code, when it actually is C++ code. So, this is giving you errors.

To fix this, right click your project and go to Properties. Go to C/C++ Build > Settings > AVR Compiler. There is a text box for "Command:" There should already be something there, and I think it would be "avr-gcc". Change it to "avr-g++" and click OK.

This should fix the error, but if not, perhaps you need to add some more code. says that you may need to add an extra function when using C++ headers. Copy and paste that block of code into your main.c file. I don't know what that block of code does :P, but it might help. For reference, I do not have that block of code; I just have the avr-g++ as my AVR Compiler, and everything still works.