first time wrinting a library

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:

//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
//IMCLibrary.ccp
#include "WProgram.h"
#include "IMCLibrary.h"


IMCLib::IMCLib(void)
{
	
}


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

&

//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:

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

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

Good.

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

Not so good.

IMCLib myLib();

Bad. The parentheses should NOT be here.

PaulS: IMCLib myLib();

Bad. The parentheses should NOT be here.

Thanks for looking at the code. But just neglecting the brackets doesn't help

undefined reference to `IMCLib::IMCLib()'

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

Best Stefan

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”:

Binary sketch size: 3356 bytes (of a 30720 byte maximum)

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

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...

ok I ashamed to admit that after 8 hours I found that the problem was that I used "IMCLib.ccp" instead of "IMC.cpp" :roll_eyes: