Unable to make a simple library work

The files and compiler result follow. Where is my error??
I have a sub-dir inside libraries named uStimer. This sub-dir contains two files named uStimer.h and uStimer. cpp I use a Mega 2560 that compiles sketches normally but not this one. the

HERE IS THE .H FILE

#ifndef USTIMER_H
#define USTIMER_H
#include <Arduino.h>

class uStimer {
private:
unsigned long uSvalue; //SANS = 0

public:
void start();

bool counting(unsigned long len); 
  
unsigned long see();

};

#endif

HERE IS THE .CPP FILE


#include "uStimer.h"
#include <Arduino.h>

unsigned long uSvalue = 0;

void start() {
  uSvalue = micros();
}

bool counting(unsigned long len) {
  if (micros() - uSvalue >= len  ) {
    return false;
  }
  return true;
}

unsigned long see() {
  return (micros() - uSvalue);
}

HERE IS THE .INO FILE

#include <uStimer.h>

uStimer chrono;  //NO COMPILER ERROR HERE
//------------------------------------------------------------
void setup() {
  Serial.begin(9600);
  delay(1000);
}
//------------------------------------------------------------
void loop() {
chrono.start();  //COMPILER ERROR: SEE BELOW
}
//------------------------------------------------------------

HERE IS THE COMPILER OUTPUT
Arduino: 1.8.19 (Windows 10), Board: "Arduino Mega or Mega 2560, ATmega2560 (Mega 2560)"

C:\Users\Serge\AppData\Local\Temp\ccnpib94.ltrans0.ltrans.o: In function `loop':

C:\Users\Serge\Documents\Arduino\Sketches\testLibrary/testLibrary.ino:11: undefined reference to `uStimer::start()'

collect2.exe: error: ld returned 1 exit status

exit status 1

Error compiling for board Arduino Mega or Mega 2560.

I don't know what it is called, but, I think, in the .cpp file the function names need to be preceded by
uStimer::
the class name.

#include "uStimer.h"
#include <Arduino.h>

unsigned long uSvalue = 0;

void uStimer::start()
{
   uSvalue = micros();
}

bool uStimer::counting(unsigned long len)
{
   if (micros() - uSvalue >= len  )
   {
      return false;
   }
   return true;
}

unsigned long uStimer::see()
{
   return (micros() - uSvalue);
}

Shouldn't the .cpp file have a constructor?

Writing a library says this in the part about writing the .cpp file.

There are a couple of strange things in this code. First is the Morse:: before the name of the function. This says that the function is part of the Morse class. You'll see this again in the other functions in the class.

I would also recommend comparing your library with the Morse example library.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.