writing a library error "undefined reference to "

brnpimenta: Hello guys, I'm learning how to write my own library, I already create the header and source codes, but when I try to use it the followed message appears "undefined reference to "

Header file:

ifndef ledBlinker_h

define ledBlinker_h

if ARDUINO >= 100

include "Arduino.h"

else

include "WProgram.h"

include "pins_arduino.h"

include "WConstants.h"

endif

class ledBlinker // it's just a general name { public: ledBlinker(int pin, int delayTime); // float blinkMe(); float fadeMe(); int on1;

private: int _pin; int _delayTime;

};

endif

brnpimenta: Source File:

include "ledBlinker.h" //declared the header file

ledBlinker::ledBlinker(int pin, int delayTime) { }

float ledBlinker::blinkMe() {

on1 = 1; return on1; } float ledBlinker::fadeMe() {}

void setup(){} void loop() {}

brnpimenta: General code that uses it:

include "ledBlinker.h" //declared the library

ledBlinker teste1(1,1); // general arguments

void setup() { Serial.begin(115200); }

void loop() { int on1 = teste1.blinkMe(); // I declared this variable in the library on1 =1; Serial.println(on1); }

Any suggestions????

Which file does the error occur in and have you posted the entire error message ?

It would have helped if you had put your code in [­code] ... [­/code] tags

the error occurs in the general code.

the total error message:

C:\Users\Bruno\AppData\Local\Temp\cc8g195k.ltrans0.ltrans.o: In function `global constructors keyed to 65535_0_test1.ino.cpp.o.1720':

cc8g195k.ltrans0.o:(.text.startup+0x64): undefined reference to `ledBlinker::ledBlinker(int, int)'

C:\Users\Bruno\AppData\Local\Temp\cc8g195k.ltrans0.ltrans.o: In function `main':

cc8g195k.ltrans0.o:(.text.startup+0x1b6): undefined reference to `ledBlinker::blinkMe()'

collect2.exe: error: ld returned 1 exit status

exit status 1 Erro compilando para a placa Arduino/Genuino Mega or Mega 2560

Please edit the post to use code tags, very hard to read now.

One thing I notice, why has fadeMe() no return type?

septillion: Please edit the post to use code tags, very hard to read now.

One thing I notice, why has fadeMe() no return type?

Thanks!

well, the objetive of this library is just to access the content of a variable inside the library.

For example, I have a variable declared in the library, but I want to access the variable and its content by using other general code, I created the general code and already declared the library, but when I try to compile it, the message occurs.

Quote tags are NOT code tags... Please edit your post again and put only your code into code tags. See How to use this forum.

Using a function to access a variable is fine. But when you declare a function you must ALWAYS define the return type. And if you don't want to return anything you must set the return type to void.