arobenko / embxx

embxx - Embedded C++ Library
GNU General Public License v3.0
263 stars 36 forks source link

Unable to use StaticFunction without `operator delete` #12

Closed trygvis closed 7 years ago

trygvis commented 7 years ago

With code similar to this:

class i2c_slave {
    typedef embxx::util::StaticFunction<void(uint8_t *)> rx_complete_t;
    rx_complete_t rx_complete;
}

I'm getting this error message:

In function `embxx::util::StaticFunction<void (unsigned char*), 12u>::InvokerBound<display_ctrl_i2c::display_ctrl_i2c()::{lambda(unsigned char*)#2}>::~InvokerBound()':
../thirdparty/embxx/embxx/util/StaticFunction.h:353: undefined reference to `operator delete(void*, unsigned int)'

which was kinda surprising given the name of the class. Am I using the class in a bad way or what am I missing?

arobenko commented 7 years ago

Hi! I'd like to refer you to the Abstract Classes chapter in my Practical Guide to Bare Metal C++ e-book. You are probably using g++ as your compiler, which generates two destruction functions for classes with destructors declared as "virtual". One of them uses operator delete. I think it would be safe to stub the missing "operator delete()" function with empty body or some kind of assertion to make sure it is not called.

trygvis commented 7 years ago

Ok, adding the function fixed it. Thanks!