When building my code I get the following "undefined reference"-errors, which I cannot get rid of. I've already tried several hints from stack overflow but nothing helps :-(. Maybe you have an idea?
I use VSCode with PlatformIO for an Arduino Uno on Mac OS.
in function `get7SegBitMap':
/Users/christian/Projekt/src/charmap7seg.cpp:70: undefined reference to 'Led7SegmentCharMap::bitMap'
/Users/christian/Projekt/src/charmap7seg.cpp:70: undefined reference to `Led7SegmentCharMap::bitMap' collect2: error: ld returned 1 exit status
The hierarchy is:
- main.cpp includes ledmatrix.hpp
- ledmatrix.cpp includes ledmatrix.hpp
- ledmatrix.hpp includes charmap7seg.hpp
- charmap7seg.cpp includes charmap7seg.hpp
charmap7seg.hpp
#pragma once
#include <Arduino.h>
class Led7SegmentCharMap {
private:
static const uint8_t bitMap[]; // will be initialized in cpp-file
uint8_t getCharMapIndex(const unsigned char outChar);
public:
// Konstruktur
Led7SegmentCharMap();
// BitMap zur Darstellung auf der 7-Segment-Anzeige für outChar ermitteln
uint8_t get7SegBitMap(const unsigned char outChar);
};
int set7SegValue(const LedMatrixPos pos, const uint8_t charBitMap);
charmap7seg.cpp
#include <Arduino.h>
#include <charmap7seg.hpp>
// Konstruktur
Led7SegmentCharMap::Led7SegmentCharMap() {
uint8_t bitMap[] = { ///< charMap contains bitmaps for 7-seg-displays
//gfedcba
0b0111111, ///< "0": Segments f, e, d, c, b, a --> bitMap[0]
0b0000110, ///< "1": Segments c, b --> bitMap[1]
0b1011011, ///< "2": Segments g, e, d, b, a --> bitMap[2]
(...)
}
(void)bitMap; // to suppress the compiler warning "unused variable"
};
uint8_t Led7SegmentCharMap::get7SegBitMap(const unsigned char outChar) {
return bitMap[getCharMapIndex(outChar)]; // <===== this is line 70
};
(...)
ledmatrix.hpp
#pragma once
#include <Arduino.h>
#include <charmap7seg.hpp>
class LedMatrix {
private:
Led7SegmentCharMap charMap;
(...)
public:
Led7SegmentCharMap(); // Konstruktor
uint8_t get7SegBitMap(const unsigned char outChar);
void LedMatrix::display(const String outString);
(...)
ledmatrix.cpp
#include <ledmatrix.hpp>
(...)
void LedMatrix::display(const String outString) {
(...) // get a char out of outString --> outChar
uint8_t charBitMap = charMap.get7SegBitMap(outChar); // get 7-seg-"bitmap"
(...)
};
(...)
My expection is that all dependencies are fulfilled (which is not true regarding the error messages). I had some trouble with initializing the bitMap-array. Maybe the undefined reference error is related to that?