| |||||
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);
}
Last Reviewed: Monday, July 10, 2006 | ||||
| |||||