Including libraries

Hi everybody.

I wrote my own “myRTC” library which is actually a simple wrapper around “RTCLib” but it only includes the functionalities I need.

“myRTC” makes use of “RTCLib”.

When I try to use use “myRTC” in the main sketch by including “myRTC.h”, I get the following compilation error:

Arduino: 1.8.10 (Windows 10), Board: “Arduino/Genuino Uno”

In file included from C:\Users\Iv�n\Documents\Arduino\libraries\myRTC/myRTC.h:9:0,

from C:\Users\Iv�n\Documents\Arduino\libraries\myRTC\myRTC.c:7:

C:\Users\Iv�n\Documents\Arduino\libraries\RTClib/RTClib.h:24:1: error: unknown type name ‘class’; did you mean ‘labs’?

class TimeSpan;

^~~~~

labs

C:\Users\Iv�n\Documents\Arduino\libraries\RTClib/RTClib.h:52:1: error: unknown type name ‘class’; did you mean ‘labs’?

class DateTime {

^~~~~

labs

C:\Users\Iv�n\Documents\Arduino\libraries\RTClib/RTClib.h:52:16: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘{’ token

class DateTime {

^

C:\Users\Iv�n\Documents\Arduino\libraries\RTClib/RTClib.h:154:1: error: unknown type name ‘class’; did you mean ‘labs’?

class TimeSpan {

^~~~~

labs

C:\Users\Iv�n\Documents\Arduino\libraries\RTClib/RTClib.h:154:16: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘{’ token

class TimeSpan {

^

C:\Users\Iv�n\Documents\Arduino\libraries\RTClib/RTClib.h:217:1: error: unknown type name ‘class’; did you mean ‘labs’?

class RTC_DS1307 {

^~~~~

labs

C:\Users\Iv�n\Documents\Arduino\libraries\RTClib/RTClib.h:217:18: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘{’ token

class RTC_DS1307 {

^

C:\Users\Iv�n\Documents\Arduino\libraries\RTClib/RTClib.h:247:1: error: unknown type name ‘class’; did you mean ‘labs’?

class RTC_DS3231 {

^~~~~

labs

C:\Users\Iv�n\Documents\Arduino\libraries\RTClib/RTClib.h:247:18: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘{’ token

class RTC_DS3231 {

^

C:\Users\Iv�n\Documents\Arduino\libraries\RTClib/RTClib.h:283:1: error: unknown type name ‘class’; did you mean ‘labs’?

class RTC_PCF8523 {

^~~~~

labs

C:\Users\Iv�n\Documents\Arduino\libraries\RTClib/RTClib.h:283:19: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘{’ token

class RTC_PCF8523 {

^

C:\Users\Iv�n\Documents\Arduino\libraries\RTClib/RTClib.h:302:1: error: unknown type name ‘class’; did you mean ‘labs’?

class RTC_Millis {

^~~~~

labs

C:\Users\Iv�n\Documents\Arduino\libraries\RTClib/RTClib.h:302:18: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘{’ token

class RTC_Millis {

^

C:\Users\Iv�n\Documents\Arduino\libraries\RTClib/RTClib.h:328:1: error: unknown type name ‘class’; did you mean ‘labs’?

class RTC_Micros {

^~~~~

labs

C:\Users\Iv�n\Documents\Arduino\libraries\RTClib/RTClib.h:328:18: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘attribute’ before ‘{’ token

class RTC_Micros {

^

C:\Users\Iv�n\Documents\Arduino\libraries\myRTC\myRTC.c:14:1: error: unknown type name ‘RTC_DS1307’

RTC_DS1307 RTC;

^~~~~~~~~~

C:\Users\Iv�n\Documents\Arduino\libraries\myRTC\myRTC.c: In function ‘rtc_init’:

C:\Users\Iv�n\Documents\Arduino\libraries\myRTC\myRTC.c:25:8: error: request for member ‘begin’ in something not a structure or union

RTC.begin();

^

C:\Users\Iv�n\Documents\Arduino\libraries\myRTC\myRTC.c: In function ‘rtc_set’:

C:\Users\Iv�n\Documents\Arduino\libraries\myRTC\myRTC.c:32:8: error: request for member ‘adjust’ in something not a structure or union

RTC.adjust( DateTime(

^

C:\Users\Iv�n\Documents\Arduino\libraries\myRTC\myRTC.c:39:25: error: expected expression before ‘)’ token

)

^

C:\Users\Iv�n\Documents\Arduino\libraries\myRTC\myRTC.c: In function ‘rtc_get’:

C:\Users\Iv�n\Documents\Arduino\libraries\myRTC\myRTC.c:47:5: error: unknown type name ‘DateTime’

DateTime rtcTime;

^~~~~~~~

C:\Users\Iv�n\Documents\Arduino\libraries\myRTC\myRTC.c:49:18: error: request for member ‘now’ in something not a structure or union

rtcTime = RTC.now();

^

C:\Users\Iv�n\Documents\Arduino\libraries\myRTC\myRTC.c:51:38: error: request for member ‘second’ in something not a structure or union

retrievedTime->clk.sec = rtcTime.second();

^

C:\Users\Iv�n\Documents\Arduino\libraries\myRTC\myRTC.c:52:38: error: request for member ‘minute’ in something not a structure or union

retrievedTime->clk.min = rtcTime.minute();

^

C:\Users\Iv�n\Documents\Arduino\libraries\myRTC\myRTC.c:53:38: error: request for member ‘hour’ in something not a structure or union

retrievedTime->clk.hour = rtcTime.hour();

^

C:\Users\Iv�n\Documents\Arduino\libraries\myRTC\myRTC.c:54:40: error: request for member ‘day’ in something not a structure or union

retrievedTime->date.day = rtcTime.day();

^

C:\Users\Iv�n\Documents\Arduino\libraries\myRTC\myRTC.c:55:40: error: request for member ‘month’ in something not a structure or union

retrievedTime->date.month = rtcTime.month();

^

C:\Users\Iv�n\Documents\Arduino\libraries\myRTC\myRTC.c:56:40: error: request for member ‘year’ in something not a structure or union

retrievedTime->date.year = rtcTime.year();

^

Multiple libraries were found for “myRTC.h”
Used: C:\Users\Iván\Documents\Arduino\libraries\myRTC
Multiple libraries were found for “Wire.h”
Used: C:\Program
Multiple libraries were found for “RTClib.h”
Used: C:\Users\Iván\Documents\Arduino\libraries\RTClib
exit status 1
Error compiling for board Arduino/Genuino Uno.

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

I don’t really what’s wrong. Both libraries (RTCLib and myRTC) are at the same directory level.
If I only use RTCLib in the main sketch, everything works perfectly.

I’m attaching also myRTC library

myRTC.c (1.69 KB)

myRTC.h (1.28 KB)

Finally I solved it. Besides some syntaxis errors which I found afterwards, the main problem was the library source file had a .c extension when it actually had to be .cpp. I changed that and now it is working.