Eclipse IDE C++ and Serial.begin()/print/whatever wants to destroy my life

Hi, i am just starting a small project conserning LEDs and cubes. http://dl.dropbox.com/u/419037/purpleorange.png

But nevermind that, I am having troubles using Serial.print() in a C++ enviornment in Eclipse. I thought it would work more or less the same as the other functions, I am having no trouble with digitalRead/Write etc.

ive built the libraries myself, and followed the eclipse guide to get myself up and running with AVR.
Here is a successful build without any use of Serial.*

I dont think the fact that im building as debug should be any issue, ive tried building as release with a different guide.

http://dl.dropbox.com/u/419037/screen1.png

With the Serial.begin()

Description Resource Path Location Type
make: *** [BlinkExample.elf] Error 1 BlinkExample C/C++ Problem
Method 'begin' could not be resolved main.cpp /BlinkExample line 38 Semantic Error
Symbol 'Serial' could not be resolved main.cpp /BlinkExample line 38 Semantic Error

Probably something silly, any advice would be appreciated.

I assume that you compiled the core functions into a library without the main loop stuff and that you compiled the core library with the same clock frequency settings as your current project. You also compiled it for the same chip.

Yes 16mzh and at328p chip for lé Uno.

Sounds like you've not defined the global object Serial. In the Arduino environment this is defined in HardwareSerial.h / HardwareSerial.cpp

Have you got this file in your library?

If so are you including HardwareSerial.h or WProgram.h?

Remember that eclipse isn't like the Arduino IDE. It doesn't do anything for you. You HAVE to include all the headers yourself, declare all functions and include all libraries for the linker.

Iain

Have a look at this post, I added a zip file that contains a template and all the settings that you need to get going.

http://arduino.cc/forum/index.php/topic,66169.0.html

Marius

Tried having a look at those files. Only path that needed obvious changing was the c:\users\marius ones.

But still, getting linking errors.

What AVR are you using?

But still, getting linking errors.

Has your error message changed?
In your original post you are getting a compilation error.

Iain

I am using the 328p at 16mHz.

The main() must be in your application and not in the core library.

I have exactly the same problem. I can use eclipse to compile->build->upload the "blink" example.
However as soon as I try use "Serial", the compiler gives the following error:

Symbol 'Serial' could not be resolved	main.cpp		line 10	Semantic Error

I use the library that arduino ide generates (copied from /tmp). I also included every .h file that I found under / directory to the eclipse project. But still I get the same error.

Does anyone know the reason for this? How may I solve this problem?

You need to include HardwareSerial.h:

#include "HardwareSerial.h"

You may need to include a path in front of the file if it's in a different location. For example in my setup I need to use

#include "Arduino/HardwareSerial.h"

as I've built the Arduino library in an Arduino folder in my workspace.

Iain

Has anyone resolved this problem as I am experiencing the same thing.

B2

Well I added the following to the top of my sketch:

extern HardwareSerial Serial;

And now it builds just fine.

B2

No special options are required, but some settings in eclipse and the general project setup are critical. Declaring HardwareSerial extern or some such thing is definitely not required, you must have a broken setup.

Look here for a detailed explanation:
http://www.arduino.cc/playground/Code/Eclipse

Be aware that there are quite a few bugs in the eclipse AVR plugin, and some in the eclipse CDT plugin which the AVR one is based on.

I agree with KiwiDude, you need not make special declarations. Have a look at this template workspace for Adruino that I created.

Place all three projects in the same work space. Compile each of the projects starting with the ArduinoCore and then the AdruinoLibraries and lastly the Template.

I use this work space for all my projects and never have any issues. I import libraries from the arduino/libraries directory when I need a new one. Recompile and go.

Marius, your template archive is an interesting idea but falls flat in several ways. Your path configuration works only on doze, and only if someone installs the same way as you. Use workspace-relative paths. Your example includes Wprogram.h which barfs on anything but the one OS around that is case-insensitive. The SD library in there compiled with errors. I didn't look further, but eclipse thought boolean was undefined.

@Kiwidude,
You are right about all issues mentioned. The template was only meant for Windows and as a result, you have to edit the paths to suit your installation. (The Joys of DOZE). I created the template to illustrate what is required to get the lot to work. Sort of a minimum requirement.
I compiled my set of libraries again and found no error. SD compiled as well.
The relative to work space paths help to get the stuff compiled. I used that option as I refer to the Core and Library object in the work space. As i recall I might have had some problems referring to outside objects.
One thing that I did, was to move the Arduino installation to the root of the drive. (c:\Arduino-022..)

I use that exact work space for all my projects without any problems. I am sure that there is a small setup issue with your project. You should look at all the settings in the tool chain setup. Especially the includes and library directories. There are also some compiler switches and more. I don't remember all.

B2:
Well I added the following to the top of my sketch:

extern HardwareSerial Serial;

And now it builds just fine.

B2

While this shouldn't be necessary, is there any downside to doing it as a quick n dirty fix?

Thanks
Geoff

Geoff
Given the code

#if defined(UBRRH) || defined(UBRR0H)
  extern HardwareSerial Serial;
#elif defined(USBCON)
  #include "usb_api.h"
#endif
#if defined(UBRR1H)
  extern HardwareSerial Serial1;
#endif
#if defined(UBRR2H)
  extern HardwareSerial Serial2;
#endif
#if defined(UBRR3H)
  extern HardwareSerial Serial3;
#endif

It is very likely it won't hurt.
However you are missing something in your eclipse environment which will cause issues later.
Look at your console window in eclipse after a build. My plugin (eclipse.baeyens.it) provided following output when compiling the file ddd.cpp
avr-g++ -I"C:\arduino-0023\arduino-0023\hardware\arduino\cores\arduino" -D__IN_ECLIPSE__=1 -DARDUINO=0023 -Wall -Os -ffunction-sections -fdata-sections -fno-exceptions -g -mmcu=atmega328p -DF_CPU=16000000UL -MMD -MP -MF"ddd.d" -MT"ddd.d" -c -o "ddd.o" -x c++ "../ddd.cpp"
not all of the options are equally important. Following items may be missing or wrong in your case:
-Os -ffunction-sections -fdata-sections -fno-exceptions -g -mmcu=atmega328p -DF_CPU=16000000UL

I'm pretty sure you are missing the -mmcu=XXXX option as this defines the __AVR_ATmegaXXXXX which on his turn defines UBRRH or UBRR0H or USBCON which defines Serial.

Best regards
Jantje

I'm having the same problem using Eclipse Indigo with Arduino Eclipse Extensions 1.2.1

I'm just compiling the following code:

#include "basic_test.h"
#include "HardwareSerial.h"

void setup() {	Serial.begin(9600);}
void loop()   {}

I get the following errors when compiling:

Method 'begin' could not be solved
Symbol 'serial' could not be solved

Declaring "extern HardwareSerial Serial" does work, so I also thought that the problem should be related to the mmcu compiler parameter, but apparently not:

Invoking: AVR C++ Compiler
avr-g++ -I"/opt/arduino-1.0/hardware/arduino/cores/arduino" -I"/opt/arduino-1.0/hardware/arduino/variants/standard" -I"/home/ludovic/Arduino/basic_test" -D__IN_ECLIPSE__=1 -DARDUINO=100 -Wall -Os -ffunction-sections -fdata-sections -fno-exceptions -g -mmcu=atmega328p -DF_CPU=16000000UL -MMD -MP -MF"basic_test.d" -MT"basic_test.d" -c -o "basic_test.o" -x c++ "../basic_test.cpp"
Finished building: ../basic_test.cpp

Any suggestions?

I am having the same issue... I can compile fine without using Serial but when I use it I get the message Symbol 'Serial' could not be resolved.

../Main.c:25: error: 'Serial' undeclared (first use in this function)
make: *** [Main.o] Error 1

I have a separate compiled AVR Cross Target Static Library library that my current AVR Cross Target Application is linked to.
HardwareSerial.h is even shown under the includes folder in project explorer.

I have both:
#include <C:\users\Sam\cpp_workspace\AVR_LIB\src\cores\arduino\HardwareSerial.h>
#include <C:\users\Sam\cpp_workspace\AVR_LIB\src\cores\arduino\HardwareSerial.h>
included at the top of my program.

I tried to extern HardwareSerial.h but got an error as well.

Any help would be much apprecieated!
Thanks!