Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undefined reference to 'operator delete(void*)'

Tags:

I'm new to C++ programming, but have been working in C and Java for a long time. I'm trying to do an interface-like hierarchy in some serial protocol I'm working on, and keep getting the error:

Undefined reference to 'operator delete(void*)' 

The (simplified) code follows below:

PacketWriter.h:

class PacketWriter { public:     virtual ~PacketWriter() {}     virtual uint8_t nextByte() = 0; } 

StringWriter.h:

class StringWriter : public PacketWriter { public:     StringWriter(const char* message);     virtual uint8_t nextByte(); } 

The constructor and nextByte functions are implemented in StringWriter.cpp, but nothing else. I need to be able to delete a StringWriter from a pointer to a PacketWriter, and i've been getting various other similar errors if I define a destructor for StringWriter, virtual or not. I'm sure it's a simple issue that I'm overlooking as a newbie.

Also, I'm writing this for an AVR chip, using avr-g++ on Windows.

Thanks

like image 863
Bracket Avatar asked Aug 10 '11 17:08

Bracket


1 Answers

Sorry for posting in an old thread, but it's still pretty high in Google's search results and if you have this problem, you really should check out this link, because there it says that you simply need to link -lstdc++ and this is what solved the problem for me.

The following line was added by the Community without highlighting it as such and instead of just adding a comment to my answer for reasons that elude me: "Or use a C++ compiler that will implicitly add the -lstdc++ option, e.g. g++."

like image 134
Alex Avatar answered Sep 29 '22 09:09

Alex