Library using another library

I’ve read a blog and a number of posts in the forum on this subject but am still not able to use one library inside another. The library I’m trying to use is TimeLib; I have it and Time.h and Time.cpp in a directory called Time under the libraries folder.

In another folder inside libraries I have D1302 and the .h and .cpp files shown below.

I’ve also included the sketch and the compiler output.

Can anyone tell me what stupid thing I’m doing that is keeping me from moving forward?

1302.h File:

#ifndef DS1302_h
#define DS1302_h
#include "Arduino.h"
#include "../Time/TimeLib.h"





class DS1302
{
	public:
		DS1302(int _SCLK_Pin, int _IO_Pin, int _CE_Pin); //Constructor assumes no battery recharging
		
		
		
	private:
		int _DS1302_SCLK_Pin; // Arduino pin for the Serial Clock
		int _DS1302_IO_Pin; 	// Arduino pin for the Data I/O
		int _DS1302_CE_Pin;  	// Arduino pin for the Chip Enable
		boolean _batRecharge;	//true if will recharge, false if will not recharge
		int _DS1302_Trickle_h; 	//0x01 if will recharge, 0x00 if will not recharge
		void fill_DS1302_struct();	//used to fill the structure
		
		struct _DS1302_struct
		{
			uint8_t Seconds:4;      // low decimal digit 0-9
		};	
               // Macros to convert the bcd values of the registers to normal integer variables.  The code uses separate
		//variables for the high byte and the low byte of the bcd, so these macros handle both bytes separately.
		#define bcd2bin(h,l)    (((h)*10) + (l))
		#define bin2bcd_h(x)   ((x)/10)
		#define bin2bcd_l(x)    ((x)%10)
};

#endif

1302.cpp File:

#include "Arduino.h"
#include "../Time/TimeLib.h"
#include "DS1302.h"

DS1302::DS1302(int _SCLK_Pin, int _IO_Pin, int _CE_Pin)
{
	_DS1302_SCLK_Pin = _SCLK_Pin;   // Arduino pin for the Serial Clock
	_DS1302_IO_Pin = _IO_Pin;    // Arduino pin for the Data I/O
	_DS1302_CE_Pin = _CE_Pin; // Arduino pin for the Chip Enable
	_DS1302_Trickle_h = 0x00;
	
	_DS1302_struct rtc;
}

DS1302::DS1302(int _SCLK_Pin, int _IO_Pin, int _CE_Pin, boolean _batRecharge)
{
	_DS1302_SCLK_Pin = _SCLK_Pin;   // Arduino pin for the Serial Clock
	_DS1302_IO_Pin = _IO_Pin;    // Arduino pin for the Data I/O
	_DS1302_CE_Pin = _CE_Pin; // Arduino pin for the Chip Enable
	if (_batRecharge)
	{
		_DS1302_Trickle_h = 0x01;
	}
	else
	{
		_DS1302_Trickle_h = 0x00;
	}
	
	
	
	
}

void DS1302::fill_DS1302_struct()
{
	// Set your own time and date in these variables.
	int _seconds    = seconds();

	// Set a time and date
	// This also clears the CH (Clock Halt) bit, 
	// to start the clock.

	// Fill the structure with zeros to make 
	// any unused bits zero
	
	_DS1302_struct rtc;
	
	memset ((char *) &rtc, 0, sizeof(rtc));

	rtc.Seconds    = bin2bcd_l( _seconds);

}

Sketch File:

#include "TimeLib.h"
#include "DS1302.h"


int SCLK_Pin = 6;
int IO_Pin = 7;
int CE_Pin = 8;
boolean batRecharge = true;
DS1302 DS1302_1(SCLK_Pin, IO_Pin, CE_Pin);
DS1302 DS1302_2(SCLK_Pin, IO_Pin, CE_Pin, batRecharge);

void setup() 
{
  Serial.begin(9600);  //Start Serial
  Serial.println("<Arduino Ready...>");

}

void loop() 
{
  Serial.println("In Loop");
  delay(10000);
  

}

Select compiler output:

M:\Arduino\Sketches\libraries\DS1302\DS1302.cpp:102:28: error: 'seconds' was not declared in this scope

  int _seconds    = seconds();

                            ^

Using library Time at version 1.5 in folder: M:\Arduino\Sketches\libraries\Time 
Using library DS1302 in folder: M:\Arduino\Sketches\libraries\DS1302 (legacy)
exit status 1
Error compiling for board Arduino/Genuino Uno.

What is wrong with using the standard include?

#include <TimeLib.h>

Thats what I did first. Then when that didn't work I went reading what I could find. There is a problem with the compiler that doesn't know where to look for the libraries when you reference them from another library. Supposedly using that format tells the compiler where to look.

This blog explains it pretty well, but I still can't seem to get it to work.

The easy fix is, or was at least, just to make sure the .ino file includes all the libraries that the other libraries need.

It's included in the sketch and is even used in the sketch so that part seems to be linked up. But the library still doesn't know what seconds() is. I've tried using the backslash instead of the slash in the included statement and get the same results. eg #include "..\Time\TimeLib.h" instead of #include "../Time/TimeLib.h".

This doesn’t look right. It tells the compiler to look for the files in the sketch folder:

#include "TimeLib.h"
#include "DS1302.h"

aarg:
This doesn’t look right. It tells the compiler to look for the files in the sketch folder:

#include "TimeLib.h"

#include “DS1302.h”

…and then in the standard include path. So in this case either include syntax works fine but #include <TimeLib.h> is more efficient.

Delta_G:
The easy fix is, or was at least, just to make sure the .ino file includes all the libraries that the other libraries need.

That hasn’t been necessary since arduino-builder was introduced in Arduino IDE 1.6.6. For example, in the bad old days you had to do this:

#include <SPI.h>
#include <Ethernet.h>

now you can just do this:

#include <Ethernet.h>

@mhessel, what version of the Arduino IDE are you using? Even if you can get it working, this sort of thing:

#include "../Time/TimeLib.h"

is really a bad idea unless the relative path is to another file inside the same library because it’s too fragile. There are hundreds, of Arduino libraries that are successfully including files from other libraries without doing anything like this so it’s certainly possible.

I'm using 1.8.5.