|
|||||||||||
|
Technical Support Support Resources
Product Information |
GCC: Linker Error (undefined Reference with C++)Information in this article applies to:
SYMPTOMThe GNU Linker gives error messages while linking an application, which contains class declarations and class instances. CAUSEThe class declaration specifies a constructor and/or destructor, but the constructor/destructor function is missing.
class clf {
public:
clf(); // Constructor (ctor)
~clf(); // Destructor (dtor)
int n1, n2, n3;
};
clf clf1; // class object
int main (void) {
return (0);
}
The Linker gives the error messages which look like the following ones: .\obj\blinky.o(.text+0x40): In function '__static_initialization_and_destruction_0': /cygdrive/c/Keil/ARM/GNU/Examples/Blinky/blinky.cpp(92): error: undefined reference to 'clf::~clf [in-charge]() 'blinky.o' (.text+0x44):blinky.cpp:92: undefined reference to 'clf::clf[in-charge]()' RESOLUTIONAdd the constructor(s) and/or destructor(s) as shown below:
class clf {
public:
clf(); // Constructor (ctor)
~clf(); // Destructor (dtor)
int n1, n2, n3;
};
clf::clf () { // define ctor
n1 = n2 = n3 = 0;
}
clf::~clf() { // define dtor
}
clf clf1; // class object
int main (void) {
return (0);
}
SEE ALSOLast Reviewed: Monday, January 4, 2021 | ||||||||||
|
|||||||||||
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.