[C++] "Undefined Reference to " error
Posted: Wed Dec 08, 2021 2:15 pm
Hi to all,
I'm having a problem with pointers.
I'm trying to create a custom Touch Keyboard library, using MCUFRIEND_kbv TFT library.
When I try to pass the pointer of the TFT instance (found in main.cpp as tft variable) to the drawKeys function of the Keyboard library (call in loop() of main.cpp as kb.drawKeys(&tft)) i get an error
"main.cpp" file
"Keyboard.h" file
"Keyboard.cpp" file
I'm unable to compile, and unable to find the problem
Thanks to whoever explains me how to try to solve the problem
Kind regards
I'm having a problem with pointers.
I'm trying to create a custom Touch Keyboard library, using MCUFRIEND_kbv TFT library.
When I try to pass the pointer of the TFT instance (found in main.cpp as tft variable) to the drawKeys function of the Keyboard library (call in loop() of main.cpp as kb.drawKeys(&tft)) i get an error
- .pio\build\esp32doit-devkit-v1\src\main.cpp.o:(.literal._Z4loopv+0x4): undefined reference to `Keyboard::drawKeys(MCUFRIEND_kbv*)'
- .pio\build\esp32doit-devkit-v1\src\main.cpp.o: In function `loop()':
- Filepath/src/main.cpp:140: undefined reference to `Keyboard::drawKeys(MCUFRIEND_kbv*)'
- //INCLUDES
- #include <SPI.h>
- #include "Adafruit_GFX.h"
- #include <MCUFRIEND_kbv.h>
- #include <Wire.h>
- #include "Fonts/FreeSerif24pt7b.h"
- #include <SD.h>
- #include "Keyboard.h"
- //TFT
- MCUFRIEND_kbv tft;
- //KeyBoard & Buttons configuration
- #define XELEMENTS 13
- #define YELEMENTS 3
- #define BUTTONMARGINS 1
- #define SIDEPADDING 6
- int _width = round(tft.width()/XELEMENTS)-(2*BUTTONMARGINS);
- int _height = _width;
- Keyboard kb(_height, _width, YELEMENTS, XELEMENTS, BUTTONMARGINS, SIDEPADDING);
- bool sd_init = false;
- void setup()
- {
- Serial.begin(250000);
- Serial.println(F("TFT LCD test"));
- pinMode(27, INPUT);
- pinMode(22, OUTPUT);
- Serial.print("TFT size is ");
- Serial.print(tft.width());
- Serial.print("x");
- Serial.println(tft.height());
- tft.reset();
- Serial.print("ID: ");
- Serial.println(tft.readID(), HEX);
- uint16_t identifier = 0x9486;
- tft.begin(identifier);
- tft.fillScreen(TFT_BLACK);
- tft.setRotation(3);
- if (SD.begin(5))
- {
- sd_init = true;
- }
- tft.fillRect(0, 0, 480, 320, TFT_BLACK);
- }
- void loop(void)
- {
- while(1)
- {
- //tft.setFont(&FreeSerif24pt7b);
- tft.fillRect(0,50,480,100, TFT_BLACK);
- kb.drawKeys(&tft);
- delay(2000);
- }
- }
- #ifndef _KEYBOARD_H
- #define _KEYBOARD_H
- #include "Adafruit_GFX.h"
- #include <MCUFRIEND_kbv.h>
- class Keyboard {
- private:
- public:
- Keyboard(short _h, short _w, short _yel, short _xel, short _bmargins, short _sidepad);
- void drawKeys(MCUFRIEND_kbv* _tft);
- };
- #endif
- #include "Keyboard.h"
- #include "MCUFRIEND_kbv.h"
- #include "Adafruit_GFX.h"
- //Defines to configurate buttons
- /*
- #define XELEMENTS 13
- #define YELEMENTS 3
- #define BUTTONMARGINS 1
- #define SIDEPADDING 6
- */
- short xEl = 0, yEl = 0, bMargins = 0, sidePadding = 0, width = 0, height = 0;
- unsigned short bBorder = 0, bBackground = 0, bTextColor = 0;
- const char Mobile_KB[3][13] PROGMEM = {
- {0, 13, 10, 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P'},
- {2, 11, 9, 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L'},
- {2, 11, 7, 'Z', 'X', 'C', 'V', 'B', 'N', 'M'},
- };
- const char Mobile_NumKeys[3][13] PROGMEM = {
- {0, 13, 10, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0'},
- {2, 11, 9, '-', '/', ':', ';', '(', ')', '&', '@', '"'},
- {2, 11, 7, '.', ',', '?', '!', '\'', '`', '$'}
- };
- const char Mobile_SymKeys[3][13] PROGMEM = {
- {0, 13, 10, '[', ']', '{', '}', '#', '%', '^', '*', '+', '='},
- {2, 11, 9, '_', '\\', '|', '~', '<', '>', '$', '"', '&'}, //4
- {2, 11, 7, '.', ',', '?', '!', '\'', '`', '@'}
- };
- Keyboard::Keyboard(short _h, short _w, short _yel, short _xel, short _bmargins, short _sidepad)
- {
- height = _h;
- width = _w;
- yEl = _yel;
- xEl = _xel;
- bMargins = _bmargins;
- sidePadding = _sidepad;
- }
- void drawKeys(MCUFRIEND_kbv &_tft)
- {
- int yoffset = height - (height * yEl);
- for (int i = 0; i < yEl; i++)
- {
- for (int x = 0; x < xEl; x++)
- {
- _tft.fillRoundRect(((width*x)+bMargins+sidePadding),(((height*i)+yoffset)+bMargins), width-(2*bMargins), height-(2*bMargins), 8, TFT_DARKCYAN);
- _tft.drawRoundRect(((width*x)+bMargins+sidePadding),(((height*i)+yoffset)+bMargins), width-(2*bMargins), height-(2*bMargins), 8, TFT_CYAN);
- }
- }
- }
Thanks to whoever explains me how to try to solve the problem
Kind regards