Pages: [1]   Go Down
Author Topic: first time wrinting a library  (Read 803 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 10
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hey Guys,

I am in the process of writing my first library (sadly without having used c or c++ before) - I hope somebody can give me some assistance - I'd appreciate it:

That's what I wrote so far:

Code:
//IMCLibrary.h
#ifndef IMCLibrary
#define IMCLibrary

#if defined(ARDUINO) && ARDUINO >= 100
  #include "Arduino.h"
#else
  #include "WProgram.h"
  #include <pins_arduino.h>
#endif

class IMCLib
{
  public:
IMCLib(); //constructor
  void Spass();
  private:
};
#endif

Code:
//IMCLibrary.ccp
#include "WProgram.h"
#include "IMCLibrary.h"


IMCLib::IMCLib(void)
{

}


void IMCLib::Spass()
{
      Serial.print("Spass!");
}

&

Code:
//Library_Test.ino
#include <IMCLibrary.h>
double TA=0.3;


IMCLib myLib();

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

void loop()
{
  myLib.Spass();  // THIS IS THE PROBLEM
  Serial.print("Phi: ");
  Serial.println(TA);
}

When compiling I get the following error:

Quote
Library_Test.cpp: In function 'void loop()':
Library_Test:15: error: request for member 'Spass' in 'myLib', which is of non-class type 'IMCLib ()()'

Could someone please help me ?

Thanks
Logged

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

Code:
#if defined(ARDUINO) && ARDUINO >= 100
  #include "Arduino.h"
#else
  #include "WProgram.h"
  #include <pins_arduino.h>
#endif
Good.

Code:
//IMCLibrary.ccp
#include "WProgram.h"
Not so good.

Code:
IMCLib myLib();
Bad. The parentheses should NOT be here.
Logged

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

Code:
IMCLib myLib();
Bad. The parentheses should NOT be here.

Thanks for looking at the code. But just neglecting the brackets doesn't help
Quote
undefined reference to `IMCLib::IMCLib()'

Do I need to change something in the header IMCLibrary.h as well ?

Best
Stefan
Logged

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

Quote
Thanks for looking at the code. But just neglecting the brackets doesn't help
It changed the error message. How does that not help?

The name of the class and the names of the files need to match. You have files named IMCLibrary.h and IMCLibrary.cpp containing a class named IMCLib.

I copied your sketch and files, renaming the header and source to match the class. Once I changed the <> on the include statement in the sketch to "" (since I have the files in the same directory as the sketch, I get only one "error":
Code:
Binary sketch size: 3356 bytes (of a 30720 byte maximum)

Logged

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

Ok changed the names of the files to IMCLib.h and IMCLib.ccp and got rid of the paraentheses after "'IMCLib myLib;" - But the error-message stays
Quote

undefined reference to `IMCLib::IMCLib()'

I just copied and pasted the Morse Library from the main page and it gives the same error... so it seems to be a more general problem...
Logged

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

ok I ashamed to admit that after 8 hours I found that the problem was that I used "IMCLib.ccp" instead of "IMC.cpp"  smiley-roll-blue
Logged

Pages: [1]   Go Up
Jump to: