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.
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.
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.
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?
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.
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.
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.
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:
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.