I have a static linked library, in it, I've define an pure virtual class name ITty and place in a file name hal.hpp, Console class inherits ITty and have all the virtual function implemented. Everything is fine until I decide to add a global variable 'Console theConsole'. No matter where I place this global variable within the static library's scope, I'll get the 'undefined reference...' error message.
hal.hpp
Code: Select all
namespace hal {
class ITty {
public:
// Attributes
virtual CONSOLE_COLOR GetForeColor() = 0;
virtual void SetForeColor(CONSOLE_COLOR fore) = 0;
virtual CONSOLE_COLOR GetBackColor() = 0;
virtual void SetBackColor(CONSOLE_COLOR back) = 0;
public:
// Operations
virtual DWORD Print(const char *, ...) = 0;
virtual void Clear() = 0;
virtual void MoveTo(const PCOORD) = 0;
virtual INT PutChar(INT) = 0;
};
}
Code: Select all
namespace hal {
class Console : public ITty {
COORD m_pos;
CONSOLE_COLOR m_back;
CONSOLE_COLOR m_fore;
public: // Constructor
Console(CONSOLE_COLOR, CONSOLE_COLOR);
~Console();
public:
// Attributes
CONSOLE_COLOR GetForeColor();
void SetForeColor(CONSOLE_COLOR fore);
CONSOLE_COLOR GetBackColor();
void SetBackColor(CONSOLE_COLOR back);
public:
// Operations
DWORD Print(const char *, ...);
void Clear();
void MoveTo(const PCOORD);
INT PutChar(INT);
private:
// Operations
int PrintBuffer(char *__restrict, const char *__restrict, va_list);
int PrintNumber(char *, int, format_specifier_t *);
int PrintString(char *, const char *, format_specifier_t *);
};
}
Code: Select all
Definition of Console class define here.
Code: Select all
namespace hal {
Console theConsole(CONSOLE_COLOR::WHITE, CONSOLE_COLOR::BLUE);
// The rest are all hal code.
...
}
Code: Select all
/home/tongko/opt/cross/x86_64-elf/lib/gcc/x86_64-elf/10.1.0/../../../../x86_64-elf/bin/ld: /home/tongko/projects/qios/obj/libhal.a(Console.o): in function `_ZN3hal7ConsoleC2ENS_13CONSOLE_COLORES1_':
/home/tongko/projects/qios/hal/Console.cpp:340: undefined reference to `_ZTVN3hal7ConsoleE'
/home/tongko/opt/cross/x86_64-elf/lib/gcc/x86_64-elf/10.1.0/../../../../x86_64-elf/bin/ld: /home/tongko/projects/qios/obj/libhal.a(Console.o): in function `_ZN3hal7ConsoleD2Ev':
/home/tongko/projects/qios/hal/Console.cpp:342: undefined reference to `_ZTVN3hal7ConsoleE'
collect2: error: ld returned 1 exit status
Code: Select all
Console::Console(CONSOLE_COLOR fore, CONSOLE_COLOR back)
: m_fore(fore)
, m_back(back) {}
Console::~Console() {
// Nothing to delete.
}
I've run out of idea what to look at, as this is just a very simple class and global variable.