Whenever i'm calling a public method i get undefined reference to

Hello,
i’m building a project to arduino mega2560, but if i’m using a method of a class i get undefined reference error.
HW.h in lib\HW\

#ifndef HW_h
#define HW_h

#include "Arduino.h"

class HW{
  public:
    HW();
    void registerToHW();
  private:
};
#endif

HW.cpp under src folder (previously it was in lib with the header)

#include "HW.h"

HW::HW(){

}
void registerToHW(){
Serial.println("blup");
}

main.cpp

#include <Arduino.h>
#include <Wire.h>
#include <IoCard.h>
#include <HW.h>

HW hw;
IoCard DO1(hw, 1, 1);

void setup() {
  Serial.begin(9600);
  Wire.begin();

 hw.registerToHW();

}

C:\Users\bocal\AppData\Local\Temp\ccZsNtbI.ltrans0.ltrans.o: In function main': <artificial>:(.text.startup+0x29c): undefined reference to HW::registerToHW()’
collect2.exe: error: ld returned 1 exit status
*** [.pio\build\megaatmega2560\firmware.elf] Error 1

It must be:

void HW::registerToHW(){
Serial.println("blup");
}

Sorry for the short reply.
I am not on my PC right now.

1 Like