Pages: 1 [2]   Go Down
Author Topic: Eclipse IDE C++ and Serial.begin()/print/whatever wants to destroy my life  (Read 8762 times)
0 Members and 1 Guest are viewing this topic.
Centurion RSA
Offline Offline
Full Member
***
Karma: 0
Posts: 166
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

@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.
Logged

Rather people think you to be a fool than you open your mouth and confirm it.

Brisbane, Australia
Offline Offline
Edison Member
*
Karma: 33
Posts: 1122
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

"There is no problem so bad you can't make it worse"
- retired astronaut Chris Hadfield

Belgium
Offline Offline
Edison Member
*
Karma: 68
Posts: 1920
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Geoff
Given the code
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
Logged

Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Offline Offline
Newbie
*
Karma: 0
Posts: 12
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

I'm just compiling the following code:
Code:
#include "basic_test.h"
#include "HardwareSerial.h"

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

I get the following errors when compiling:
Code:
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:

Code:
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?
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 1
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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!
Logged

Belgium
Offline Offline
Edison Member
*
Karma: 68
Posts: 1920
Arduino rocks; but with my plugin it can fly rocking the world ;-)
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

@Samk and @ludovic
If you want some help I think it is important to state what you are using.
I mean are you using eclipse CDT purely?
Are you using avr-eclipse plugin?
Are you using the arduino eclipse plugin?
Without this basic info it is hard to give help.
@ludovic
I have never heard of "Arduino Eclipse Extensions 1.2.1". Where did you find this?

Best regards
Jantje
Logged

Do not PM me a question unless you are prepared to pay for consultancy.
Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -

Pages: 1 [2]   Go Up
Jump to: