I am a beginer and I am trying to create my first library.
My terminal display that error message:
sim908_v6.cpp.o: In function __static_initialization_and_destruction_0': /Applications/sim908_v6.ino:3: undefined reference to Sim908::Sim908()'
sim908_v6.cpp.o: In function loop': /Applications/sim908_v6.ino:16: undefined reference to Sim908::blinkLed(int, int, int)'
May I ask you to to help me about that error message?
Here is my code.
First I create two files in
/libraries/Sim908/Sim908.h
/*
Sim908.h - Library
*/
#ifndef Sim908_h
#define Sim908_h
#include "Arduino.h"
class Sim908{
public:
Sim908();
void blinkLed(int lPin, int nBlink, int msec);
private:
};
#endif
/libraries/Sim908/Sim908.cpp
#include "Arduino.h"
#include "Sim908.h"
Sim908::Sim908(){
}
void Sim908::blinkLed(int lPin, int nBlink, int msec) {
if (nBlink) {
for (int i = 0; i < nBlink; i++) {
digitalWrite(lPin, HIGH);
delay(msec);
digitalWrite(lPin, LOW);
delay(msec);
}
}
}
and
Sim908_v6.ino.
#include <Sim908.h>
Sim908 sim908;
int green = 12;
void setup()
{
pinMode(green, OUTPUT);
}
void loop()
{
sim908.blinkLed(green,1,1000);
delay(3000);
}
Hello,
Did you try the code,
I rename the file to Sim908 (Ido not think it cause the error) and the probleme is the same.
When I compile, I still get that error message:
sim908.cpp.o: In function __static_initialization_and_destruction_0': /Applications/sim908.ino:3: undefined reference to Sim908::Sim908()'
sim908.cpp.o: In function loop': /Applications/sim908.ino:28: undefined reference to Sim908::blinkLed(int, int, int)'
Sketch uses 1,260 bytes (3%) of program storage space. Maximum is 32,256 bytes.
Global variables use 12 bytes (0%) of dynamic memory, leaving 2,036 bytes for local variables. Maximum is 2,048 bytes.
my library is called Sim908.
It is in folder
/libraries/Sim908/
and the two files are name Sim908.h and Sim908.cpp. Those two files are in folder /libraries/Sim908/
I created a file Sim908_v6.ino and I imported the Sim908 library. I do not think the ino file has to have the same name than the library you want to import otherwise you will not be able to import other libraries...
I close Arduino IDE, restart the Macbook and reopen my ino file.
The problem is still the same.
I commented the function //sim908.blinkLed(green,1,1000); (because is another error)
and I compiled and got that error:
sim908_v6.cpp.o: In function __static_initialization_and_destruction_0': /Applications/sim908.ino:3: undefined reference to Sim908::Sim908()'
I red your link, but is it the same problem of me? I do not get an error message stating: "...was not declared in this scope".
void Sim908::blinkLed(int lPin, int nBlink, int msec) {
if (nBlink) {
for (int i = 0; i < nBlink; i++) {
digitalWrite(lPin, HIGH);
delay(msec);
digitalWrite(lPin, LOW);
delay(msec);
}
}
}
and in Sim908.h file
class Sim908{
public:
Sim908();
void blinkLed(int lPin, int nBlink, int msec);
private:
};
When I compile my code, the terminal display that error:
sim908_v6.ino: In function 'void loop()':
sim908_v6:30: error: cannot call member function 'void Sim908::blinkLed(int, int, int)' without object
Is a problem of type? I tried several solution but without success. may I ask you an help?
Many thank