xBee.h doesn't compile with leonardo - Serial problem

I am trying to use xbee.h (GitHub - andrewrapp/xbee-arduino: Arduino library for communicating with XBee radios in API mode) with the new Leonardo. I get this error when I verify the sketch:
769: error: cannot convert 'Serial_' to 'HardwareSerial' in assignment

I assume it has something to do with the Leonardo not using serial by default and you have to use Serial1 or something, but I don't know what code to change to fix this. Can anyone help?

--Scott

Replace line 769 of XBee.cpp

_serial = &Serial;

with

_serial = &Serial1;

That worked, thanks. In the \libraries\ folder I created a new directory called \XBee_Leo and copied XBee.h and XBee.cpp in there and renamed them to XBeeLeo.h and XBeeLeo.cpp. In the XBeeLeo.cpp I made the serial1 change and changed #include XBee.h to #include XBeeLeo.h. In my sketch I just changed the include from <XBee.h> to <XbeeLeo.h> and all is good.

It would be nice if one library could compile both Leonardo boards and non-Leonardo boards. I tried some stuff with #ifdef, but it didn't work. Here's what I tried:
First I changed added a #define to my sketch:

#define LEONARDO
#include <XBee.h>

In XBee.cpp, I changed

_serial = &Serial;

to

#ifdef LEONARDO
   _serial = &Serial1;
#else
   _serial = &Serial;
#endif

But this didn't work.

This does not work because the defines and includes are rearranged before fed to the compiler.

But you can change your library this way and you don't have to do anything special. If you choose the Leonardo as the board type automatically the correct code is generated.

#ifdef defined(USBCON)
   _serial = &Serial1;
#else
   _serial = &Serial;
#endif

I made the change and made sure I closed then re-opened the Arduino IDE, but my sketch didn't compile when I selected the Leonardo board. I got this error:

/Volumes/srg/Arduino Sketches/libraries/XBee/XBee.cpp: In constructor 'XBee::XBee()':
/Volumes/srg/Arduino Sketches/libraries/XBee/XBee.cpp:774: error: cannot convert 'Serial_' to 'HardwareSerial' in assignment

Sorry, my fault, had a copy/paste error in my posted code. Should be an #if and not an #ifdef:

#if defined(USBCON)
   _serial = &Serial1;
#else
   _serial = &Serial;
#endif

That worked, thanks!

I am having the same problem with the MICRO; I tried the fix described here but it does not work.

I am putting the

#if defined(USBCON)
   _serial = &Serial1;
#else
   _serial = &Serial;
#endif

at the beginning of the xbee.cpp file

is there something else I should do???

Bill

You have to replace the line

_serial = &Serial;

with the code you posted. If you just add the code at the beginning it has absolutely no effect.