Pages: [1]   Go Down
Author Topic: problem with creating a library  (Read 486 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i've tried  to learn hot to create a new library , i did it all just as explained buy the site and still i had an error showing

this is the error
sketch_oct27a.cpp.o: In function `setup':
C:\Users\hagai\AppData\Local\Temp\build8272096594347651372.tmp/sketch_oct27a.cpp:8: undefined reference to `Led::Led(int)'

this is my code

header:
Code:
#ifndef Led_h
#define Led_h

#include "Arduino.h"

class Led
{
  public:
    Led (int pin);
    void on();
    void off();
  private:
    int _pin;
};

#endif

source:
Code:
#include "Arduino.h"
#include "Led.h"
Led::Led(int pin)
{
  pinMode(pin, OUTPUT);
  _pin = pin;
}

void Led::on()
{
  digitalWrite(_pin, HIGH);
}

void Led::off()
{
  digitalWrite(_pin, LOW);
}

the sketch:
Code:
#include <Led.h>

Led led1(13);

void setup()
{
}
void loop()
{
  led1.on();
}

thanks in advance

« Last Edit: October 27, 2012, 04:21:44 pm by HagaiOfer » Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 220
Posts: 13836
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

you might need to restart the IDE before it "sees" your new library.

Please use the # button to post code, it will give you [ code] tags to make it look better (easier to read).
you can modify your post to do so. JUst select the .h part and press # (above the smileys)

Can you post your sketch that uses the library too?
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50086
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Which version of the IDE are you using? I can pretty well guess that it is 1.0.1, which does not think that missing include files are a fatal error.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes im using 1.0.1 , what i need to do to clear this error?
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50086
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
what i need to do to clear this error?
Shut down the IDE. Download the library. Install it in the right place. Restart the IDE. Keep your fingers crossed.

After the third or fourth time you install a library, the 5th step won't be required any more.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

still not working.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50086
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
still not working.
Then uninstall 1.0.1 and install 1.0. procreate that crappy version.
Logged

Denmark
Offline Offline
Edison Member
*
Karma: 36
Posts: 1082
Happy Hobbyist
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

HagaiOfer, I just tried your library and it worked first time.
I use version 1.01 (and Windows Vista if that matters)

I'm afraid I don't understand which include files is missing
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i just tried using both versions and still showing me the error , at least now i know its not something that i've done.
thanks again.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 631
Posts: 50086
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
i just tried using both versions and still showing me the error
You need to post more details, then. For instance, what, exactly, is the source file for the Led class called? What is the header file called?
Logged

Saskatchewan
Offline Offline
Sr. Member
****
Karma: 19
Posts: 364
When the going gets weird, the weird turn pro. - Hunter S. Thompson
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I quickly went into my Sketchbook/libraries folder and created a Led folder and inside that created a Led.h and a Led.cpp. I cut and pasted from the code here and it compiled fine with the sketch provided here.

I'm using 1.01 on Linux.



Logged

Pages: [1]   Go Up
Jump to: