So just to recap I seem to be having linker errors for this example to use the Serial.print function from a library as coded in multiple tabs in a sketch:
.ino file
#include "MyLibrary.h"
MyLibrary myLibrary(Serial);
void setup() {
myLibrary.test();
}
void loop() {}
.cpp file
#include "HardwareSerial.h"
class MyLibrary {
public:
//pass a reference to a Print object
MyLibrary( HardwareSerial &print ) {
printer = &print; //operate on the address of print
printer->begin(9600);
}
void test() {
printer->println("Hello library with serial connectivity!");
}
private:
HardwareSerial* printer;
};
.h file
#ifndef _EXAMPLE_SPLIT_H
#define _EXAMPLE_SPLIT_H
#endif
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
class MyLibrary {
public:
//pass a reference to a Print object
MyLibrary( HardwareSerial &print );
void test();
private:
HardwareSerial* printer;
};
Errors:
HardwareSerialClassExampleSplit.cpp.o: In function __static_initialization_and_destruction_0': C:\Users\Kb\AppData\Local\Temp\build5255053454461430477.tmp/HardwareSerialClassExampleSplit.cpp:7: undefined reference to
MyLibrary::MyLibrary(HardwareSerial&)'
HardwareSerialClassExampleSplit.cpp.o: In function setup': C:\Users\Kb\AppData\Local\Temp\build5255053454461430477.tmp/HardwareSerialClassExampleSplit.cpp:11: undefined reference to
MyLibrary::test()'
Thanks in advance for advice on how to resolve this or if this is not allowed for some reason.
Cheers Kb