Undefined reference to Serial1

Hello,

I’m trying to make my own little lib with some function and classes, one of the class is basicly a serial writer (with some extra options). The problem is that in Eclipse (Yes everything is set up allright, I followed the tutorial correctly) Serial1 could not be resolved.

My code (this is the cpp file, headers are just basic stuff)

#include <WProgram.h>
#include "proxyLayer.h"
#include "serialConnect.h"

void PlayerClient::writeToSerial(int16_t data) {
	Serial1.write(data);

}

If I compile it with eclipse it says It didnt find any errors and compiles just allright but then if I implement the library in another project it gives me following errors

**** Build of configuration Debug for project mainProject ****

make all 
Building target: mainProject.elf
Invoking: AVR C++ Linker
avr-gcc --cref -s -Os -o"mainProject.elf"  ./main.o   -lMegaCore -lIrobotCore -lm -Wl,-Map,mainProject.map,--cref -Wl,--gc-sections -L/home/jan/eclipse/Arduino/IrobotCore -L/home/jan/eclipse/Arduino -mmcu=atmega2560
/home/jan/eclipse/Arduino/IrobotCore/libIrobotCore.a(serialConnect.o): In function `PlayerClient::drive(int, int)':
serialConnect.cpp:(.text._ZN12PlayerClient5driveEii+0x10): undefined reference to `Serial1'
serialConnect.cpp:(.text._ZN12PlayerClient5driveEii+0x12): undefined reference to `Serial1'
serialConnect.cpp:(.text._ZN12PlayerClient5driveEii+0x18): undefined reference to `HardwareSerial::write(unsigned char)'
serialConnect.cpp:(.text._ZN12PlayerClient5driveEii+0x20): undefined reference to `HardwareSerial::write(unsigned char)'
serialConnect.cpp:(.text._ZN12PlayerClient5driveEii+0x28): undefined reference to `HardwareSerial::write(unsigned char)'
serialConnect.cpp:(.text._ZN12PlayerClient5driveEii+0x30): undefined reference to `HardwareSerial::write(unsigned char)'
serialConnect.cpp:(.text._ZN12PlayerClient5driveEii+0x38): undefined reference to `HardwareSerial::write(unsigned char)'
/home/jan/eclipse/Arduino/IrobotCore/libIrobotCore.a(serialConnect.o): In function `PlayerClient::start()':
serialConnect.cpp:(.text._ZN12PlayerClient5startEv+0x6): undefined reference to `Serial1'
serialConnect.cpp:(.text._ZN12PlayerClient5startEv+0x8): undefined reference to `Serial1'
serialConnect.cpp:(.text._ZN12PlayerClient5startEv+0x14): undefined reference to `HardwareSerial::begin(long)'
serialConnect.cpp:(.text._ZN12PlayerClient5startEv+0x1c): undefined reference to `HardwareSerial::write(unsigned char)'
make: *** [mainProject.elf] Error 1

**** Build Finished ****

Sooo there is a problem I guess, the point is what? Could this be my IDE eclipse or just something else?

Thanks alot!

Have you got the board selection macros set correctly?

AWOL: Have you got the board selection macros set correctly?

Never heard of that, what do you mean? Can you link me to a tutorial how to set them up in Eclipse?

Thanks!

Sorry, don't use Eclipse for Arduino. You can see the macros in the serial sources.

AWOL:
Sorry, don’t use Eclipse for Arduino.
You can see the macros in the serial sources.

Can you specify a file name or location (typical)?

Also, why not? Most programmer’s that use a more advanced IDE use eclipse (there is a page on arduino.cc how to set everything up).

thanks

Also, why not?

Because, out of the box, the Arduino IDE just works. Can you say that for Eclipse? Apparently not, or you wouldn’t be here.

Can you specify a file name or location (typical)?

find / -name "*.[ch]" | xargs grep Serial1

(If you know where your installation is, you may be able to replace the "/" with something a little more precise)

PaulS:

Also, why not?

Because, out of the box, the Arduino IDE just works. Can you say that for Eclipse? Apparently not, or you wouldn't be here.

After following the tutorial on arduino.cc it also works with eclipse, the problem is that advanced IDE functions are not available in the Arduino IDE, that's were eclipse comes in. If you want to make some advanced libs, you really need a more advanced IDE.

Anyway back to topic, thanks for the search line, I'll look into it, still wondering if I should include another library or set some settings or define some variables...

Thanks

define some variables

By then, it is far too late.

AWOL: define some variables

By then, it is far too late.

?? What should i define?

Let me show you the technique. You need some sort of "find in files" thing. I am using Crimson Editor on my Windows machine, but what AWOL said would be another way.

Searching for Serial1 (the thing you are wanting) reveals this, in HardwareSerial.cpp:

#if defined(UBRR1H)
  HardwareSerial Serial1(&rx_buffer1, &UBRR1H, &UBRR1L, &UCSR1A, &UCSR1B, &UDR1, RXEN1, TXEN1, RXCIE1, UDRE1, U2X1);
#endif

So, we need UBRR1H defined, or the variable Serial1 is not created.

For that to be defined you need to have the "processor/board type" correctly set up in the IDE (or some file).

Most programmer's that use a more advanced IDE use eclipse ...

I don't use Eclipse personally, but I assume that if it is advanced, it lets you specify what type of processor (board) you have.