Errors making a library

I'm trying to write a library but when I use it get an errors.

This is my HomeAlarm.h

#ifndef HomeAlarm
#define HomeAlarm

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

class HomeAlarm{
	public: 
		HomeAlarm();
		void ErrSound();
	private:
		int _spkPin;
};
#endif

This is HomeAlarm.cpp

#include "HomeAlarm.h";

HomeAlarm::HomeAlarm(){
	_spkPin = 13;
}
void HomeAlarm::ErrSound(){
	tone(speakerPin, 200);
	delay(500);
	noTone(speakerPin);
	tone(speakerPin, 300);
	delay(500);
	noTone(speakerPin);
}

This is the calling

#include <HomeAlarm.h>

HomeAlarm alarma();//Buzzer pin

void setup(){
  alarma.ErrSound();
}
void loop(){
  
}

Those are the error that I get
In file included from sketch_jul08a.ino:1:
C:\Program Files (x86)\Arduino\libraries\HomeAlarm/HomeAlarm.h:14: error: expected unqualified-id before ')' token
C:\Program Files (x86)\Arduino\libraries\HomeAlarm/HomeAlarm.h:12: error: an anonymous struct cannot have function members
C:\Program Files (x86)\Arduino\libraries\HomeAlarm/HomeAlarm.h:18: error: abstract declarator '' used as declaration
sketch_jul08a:3: error: expected constructor, destructor, or type conversion before ';' token
sketch_jul08a.ino: In function 'void setup()':
sketch_jul08a:6: error: 'alarma' was not declared in this scope

Thx for help me.

Is this a method:

		int _spkPin;

?

Where are the "()"?

Try:

		int _spkPin();

_spkPin is a private variable.

Yes it is! Now I see it in the constructor. Sorry.

Try change:

#ifndef HomeAlarm
#define HomeAlarm

To:

#ifndef HOME_ALARM
#define HOME_ALARM

Yes, it resolve the error thx, but why I need to write HOME_ALARM and not HomeAlarm.
And the other question is, why now I get this messages:
sketch_jul08a.ino: In function 'void setup()':
sketch_jul08a:6: error: request for member 'ErrSound' in 'alarma', which is of non-class type 'HomeAlarm ()()'

This is the sketch

#include <HomeAlarm.h>

HomeAlarm alarma();//Buzzer pin

void setup(){
  alarma.ErrSound();
}
void loop(){
  
}

I'm make changes in the .CPP and .H
This is my .H

#ifndef HOME_ALARM
#define HOME_ALARM

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

class HomeAlarm{
	public: 
		HomeAlarm();
		void ErrSound();
	private:
		int _spkPin();
};
#endif

This is my .CPP

#include "HomeAlarm.h";

HomeAlarm::HomeAlarm(){
	_spkPin = 13;
}
void HomeAlarm::ErrSound(){
	tone(_spkPin, 200);
	delay(500);
	noTone(_spkPin);
	tone(_spkPin, 300);
	delay(500);
	noTone(_spkPin);
}

This is my sketch

#include <HomeAlarm.h>

HomeAlarm alarm();//Buzzer pin

void setup(){
  alarm.ErrSound();
}
void loop(){
  
}
HomeAlarm alarma();//Buzzer pin

What is this supposed to be ? Are you creating an instance of the class ? Prototyping a function ? It's probably wrong.

#include <HomeAlarm.h>

HomeAlarm alarma();//Buzzer pin

void setup(){
  alarma.ErrSound();
}
void loop(){
  
}

alarma?

foca:
Yes, it resolve the error thx, but why I need to write HOME_ALARM and not HomeAlarm.
(...)

They are 2 different things. One thing is your class that have name HomeAlarm. the other thing is the define that is created at the beginning of your .h file to prevent that the file be called more that one time. At the first time that the file HomeAlarm.h is called, the HOME_ALARM is not "defined", so the #ifndef is executed and so you all .h file (and also the HOME_ALARM is defined).
If in other place of your project, you call other time your HomeAlarm.h you don't get errors.

but why I need to write HOME_ALARM and not HomeAlarm.

You are trying to use the same name for the name of the class, and for the #define name which you are using to avoid the multiple inclusion of the definition.

The class name and the #define name need to be slightly different.

You can probably get rid of that obsolete wprogram stuff now.

Now I realise that are other errors. So, try:

#include <HomeAlarm.h>

HomeAlarm alarma;//Buzzer pin

void setup(){
  alarma.ErrSound();
}
void loop(){
  
}

and:

#include "HomeAlarm.h";

HomeAlarm::HomeAlarm(){
	_spkPin = 13;
}
void HomeAlarm::ErrSound(){
	tone(_spkPin, 200);
	delay(500);
	noTone(_spkPin);
	tone(_spkPin, 300);
	delay(500);
	noTone(_spkPin);
}

with the old .h:

#ifndef HOME_ALARM
#define HOME_ALARM

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

class HomeAlarm{
	public: 
		HomeAlarm();
		void ErrSound();
	private:
		int _spkPin;
};
#endif

After the code completely working, and to understand why you should use HOME_ALARM and HomeAlarm. Try this thing, use this .h:

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

class HomeAlarm{
	public: 
		HomeAlarm();
		void ErrSound();
	private:
		int _spkPin;
};

I remove the 2 first lines and the last, so a delete the definition of HOME_ALARM.
Try to compile it. It should compile well.

Now try to use this sketch:

#include <HomeAlarm.h>
#include <HomeAlarm.h>

HomeAlarm alarma;//Buzzer pin

void setup(){
  alarma.ErrSound();
}
void loop(){
  
}

I only add a second line:

#include <HomeAlarm.h>

It should not be able to compile.

Now, do you understand the need of use the HOME_ALARM and why it should be different of the name of your class? They are different things.

EDIT: Can you change the subject of the first post to "[SOLVED]..."?

A LOT OF THX michinyon and luisilva I got it for the explain of HOME_ALARM.
And thxsteinie44 and michinyon I just trying to make an instance.
luisilva a lot Thx.

Thx for the help, now I can continue coding.

but why I need to write HOME_ALARM and not HomeAlarm.

The usual way to create an inclusion guard is:

#ifndef HomeAlarm_h
#define HomeAlarm_h

The symbol created by the #define needs to be unique. Adding the _h to the end ensures that the name doesn't conflict with the class name.

Hello, now I got some new problems. I hop that you can help me.
In my .CPP I'm trying to call new instanses from other libraries. So this is my code:

//Keypad
#include "../Keypad/Keypad.h"
_ROWS = 4;
_COLS = 4;
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte colPins[COLS] = {2,3,4,5};
byte rowPins[ROWS] = {6,7,8,9};

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );


//LCD I2C 16x2 //DFRobot.com
#include "../Wire/Wire.h"
#include "../LiquidCrystal_I2C/LiquidCrystal_I2C.h"
LiquidCrystal_I2C LCD(0x20,16,2);

#include "HomeAlarm.h";

HomeAlarm::HomeAlarm(int spkPin){
	_spkPin = spkPin;
}
void HomeAlarm::ConfirmSound(){
	tone(_spkPin, 400);
	delay(500);
	noTone(_spkPin);
	tone(_spkPin, 500);
	delay(500);
	noTone(_spkPin);
}
void HomeAlarm::ErrSound(){
	tone(_spkPin, 200);
	delay(500);
	noTone(_spkPin);
	tone(_spkPin, 300);
	delay(500);
	noTone(_spkPin);
}
void HomeAlarm::keySound(){
	tone(_spkPin, 750);
	delay(100);
	noTone(_spkPin);
}

This is my new .h

#ifndef HOME_ALARM
#define HOME_ALARM

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

class HomeAlarm{
	public: 
		HomeAlarm(int spkPin);
		void ConfirmSound();
		void ErrSound();
		void keySound();
	private:
		int _spkPin;
		int _LCD;
		byte _ROWS;
		byte _COLS;
};
#endif

P.D: If I use only the sketch of lcd or Keypad I can use it.

There are a few things that I don't like, but is hard to say what is the error without the log. Can you add the log like you did the first time?

Sorry I forget it
This is my new .CPP

//Keypad
#include "../Keypad/Keypad.h"
const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1','2','3','A'},
  {'4','5','6','B'},
  {'7','8','9','C'},
  {'*','0','#','D'}
};
byte colPins[COLS] = {2,3,4,5};
byte rowPins[ROWS] = {6,7,8,9};

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );



//LCD I2C 16x2 //DFRobot.com
#include "../Wire/Wire.h"
#include "../LiquidCrystal_I2C/LiquidCrystal_I2C.h"
LiquidCrystal_I2C LCD(0x20,16,2);

#include "HomeAlarm.h";

HomeAlarm::HomeAlarm(int spkPin){
	Serial.begin(9600);
	_spkPin = spkPin;
	//initialize the lcd
	lcd.init();                      // initialize the lcd 
	lcd.backlight();
	lcd.home();
}
void HomeAlarm::ConfirmSound(){
	tone(_spkPin, 400);
	delay(500);
	noTone(_spkPin);
	tone(_spkPin, 500);
	delay(500);
	noTone(_spkPin);
}
void HomeAlarm::ErrSound(){
	tone(_spkPin, 200);
	delay(500);
	noTone(_spkPin);
	tone(_spkPin, 300);
	delay(500);
	noTone(_spkPin);
}
void HomeAlarm::keySound(){
	tone(_spkPin, 750);
	delay(100);
	noTone(_spkPin);
}

And this this my new .h

#ifndef HOME_ALARM
#define HOME_ALARM

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

class HomeAlarm{
	public: 
		HomeAlarm(int spkPin);
		void ConfirmSound();
		void ErrSound();
		void keySound();
	private:
		int _spkPin;
};
#endif

This is the sketch

#include <HomeAlarm.h>

HomeAlarm alarm(10);//Buzzer pin

void setup(){
  alarm.ConfirmSound();
}
void loop(){
  
}

And the error log
HomeAlarm\HomeAlarm.cpp.o: In function __static_initialization_and_destruction_0': C:\Program Files (x86)\Arduino\libraries\HomeAlarm/HomeAlarm.cpp:14: undefined reference to Keypad::Keypad(char*, unsigned char*, unsigned char*, unsigned char, unsigned char)'
C:\Program Files (x86)\Arduino\libraries\HomeAlarm/HomeAlarm.cpp:21: undefined reference to `LiquidCrystal_I2C::LiquidCrystal_I2C(unsigned char, unsigned char, unsigned char)'
P.D: If I use separate in the sketches don't have errors

I'm not very good with C++, but I don't like this:

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );

and this:

LiquidCrystal_I2C LCD(0x20,16,2);

You must do this in the "main file" (the sketch that the user of your library makes). At this time, you don't know for example what is the I2C address of the I2C LCD.

So, I think you must do something like:

extern Keypad keypad;
(...)
extern LiquidCrystal_I2C LCD;

And then in your main file you create the instances. (I don't have sure about this, but is the logic idea to me)
Other option is create the object instances in the constructor of your object, I think.

But the real errors are about finding the path to the .h files. Did you try with simply:

#include <Wire.h>
#include "Keypad.h"
#include "LiquidCrystal_I2C.h"

Now I'm trying this but I get this errors:
HomeAlarm\HomeAlarm.cpp.o: In function HomeAlarm': C:\Program Files (x86)\Arduino\libraries\HomeAlarm/HomeAlarm.cpp:25: undefined reference to Keypad::Keypad(char*, unsigned char*, unsigned char*, unsigned char, unsigned char)'
C:\Program Files (x86)\Arduino\libraries\HomeAlarm/HomeAlarm.cpp:28: undefined reference to LiquidCrystal_I2C::LiquidCrystal_I2C(unsigned char, unsigned char, unsigned char)' C:\Program Files (x86)\Arduino\libraries\HomeAlarm/HomeAlarm.cpp:29: undefined reference to LiquidCrystal_I2C::init()'
C:\Program Files (x86)\Arduino\libraries\HomeAlarm/HomeAlarm.cpp:30: undefined reference to LiquidCrystal_I2C::backlight()' C:\Program Files (x86)\Arduino\libraries\HomeAlarm/HomeAlarm.cpp:31: undefined reference to LiquidCrystal_I2C::home()'
My .CPP is

//Keypad
#include "../Keypad/Keypad.h"

//LCD I2C 16x2 //DFRobot.com
#include "../Wire/Wire.h"
#include "../LiquidCrystal_I2C/LiquidCrystal_I2C.h"


#include "HomeAlarm.h";

HomeAlarm::HomeAlarm(int spkPin){
	Serial.begin(9600);
	_spkPin = spkPin;
	//Keypad
	const byte ROWS = 4;
	const byte COLS = 4;
	char keys[ROWS][COLS] = {
	  {'1','2','3','A'},
	  {'4','5','6','B'},
	  {'7','8','9','C'},
	  {'*','0','#','D'}
	};
	byte colPins[COLS] = {2,3,4,5};
	byte rowPins[ROWS] = {6,7,8,9};
	Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
	
	//initialize the lcd
	LiquidCrystal_I2C lcd(0x20,16,2);
	lcd.init();
	lcd.backlight();
	lcd.home();
}
void HomeAlarm::ConfirmSound(){
	tone(_spkPin, 400);
	delay(500);
	noTone(_spkPin);
	tone(_spkPin, 500);
	delay(500);
	noTone(_spkPin);
}
void HomeAlarm::ErrSound(){
	tone(_spkPin, 200);
	delay(500);
	noTone(_spkPin);
	tone(_spkPin, 300);
	delay(500);
	noTone(_spkPin);
}
void HomeAlarm::keySound(){
	tone(_spkPin, 750);
	delay(100);
	noTone(_spkPin);
}

My .h

#ifndef HOME_ALARM
#define HOME_ALARM

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

class HomeAlarm{
	public: 
		HomeAlarm(int spkPin);
		void ConfirmSound();
		void ErrSound();
		void keySound();
	private:
		int _spkPin;
};
#endif

And the sketch

#include <HomeAlarm.h>

HomeAlarm alarm(10);//Buzzer pin

void setup(){
  alarm.ConfirmSound();
}
void loop(){
  
}

No one has ever been able to make one library include another one, and hide that fact from the sketch. You will NOT be the first to accomplish this.