Racking my brain for the past few days over what I believe is a linker issue. I have a simple .h and .cpp file defined but when I try to compile the .ino program I receive an undefined reference error. I am using VS Code with CLI 1.7.1. Targeting a Boron on 1.4.0. Any guidance would greatly be appreciated!
Exact error:
undefined reference to `RTC_DS3231::begin()'
collect2: error: ld returned 1 exit status
Here is the code below:
rtc.ino
SerialLogHandler logHandler(ALL_LEVEL);
SYSTEM_MODE(SEMI_AUTOMATIC);
#include "../lib/Adafruit-RTClib/RTClib.h"
RTC_DS3231 rtc;
void setup() {
Serial.begin(115200); //open serial console
delay(10000); //10 seconds
rtc.begin();
}
void loop() {
//Do nothing right now
}
Huh? 1.47.0 is the most recent CLI version.
Can you check again via particle --version?
When your project structure is correct your include should not require the path
#include "RTClib.h"
should suffice.
Although commonly the main header file of a library should have the same name as the library. If you can't or don't want to change that, add a header file to the library like this
Hey ScruffR,
Thanks for the response. Yes, I gave you the wrong version. I am using 1.47.0. I renamed the library to RTClib which matches the header file. I changed the bool to boolean so they both match. Still the same undefined reference error. If I donβt specify the path, the library is not found. The RTClib is in a lib folder at the root of the project. Where is the correct place? Here is a screenshot of my project directory.
The structure of the library is not correct IMO and it is missing a library.properties file.
This would be how a valid project structure should look like