Tuesday 6 October 2015

Importing mbed libraries to Em::Blocks - do not get caught by RTTI and "undefined reference to typeinfo" !

Ok, so you got some project that you have taken from mbed online compiler and imported to Em::Blocks. It's compiling fine.

And then you decide, oh yeah I need another library from mbed, so I'll just download it and add the files into my project in Em::Blocks.

Easy, right ? WRONG !!!

If you have any virtual functions i.e. polymorphic C++ classes, you will run into this:

.objs\~#\adafruit-gfx-library\adafruit_gfx.o:(.rodata._ZTI12Adafruit_GFX+0x8)||undefined reference to `typeinfo for mbed::Stream'|

Namely, you will run into "undefined reference to typeinfo' error given by the linker.

And you will be scratching your head.

And you will be reading up on your knowledge of polymorhism. Speaking of which, this is the most through and informative description I have ever seen: http://www.drbio.cornell.edu/pl47/programming/TICPP-2nd-ed-Vol-one-html/Chapter15.html  

Ok back to the story.

And you will be wondering what on earth is going wrong. Some inherited classes with virtual functions work, while others do not. What on earth could it be ? Malformed destructors ? Missing definitions ? Missing RTTI ?

... can't be RTTI. RTTI was deprecated in mbed a long time ago. 

... can't be RTTI. I am already building mbed libs from source, not the ready-built binaries.

So it can't be RTTI, right ? WRONG BUDDY, IT IS THE *¤%# RTTI.

(Sorry for outburst, took me a _while_ to find this problem)

Why ? Because imported files get different settings than files that were within the original .eix exported from mbed.

When importing an .EIX file every c++ file is given it’s own properties section in the .ebp file, where as the regular c-files relies on global options. If I add a c++ file after the import, this file doesn’t get its own section of options. It has to rely on the global options, which are for gnu99 c and not gnu++98.
Long story short. Turn RTTI generation off (-fno-rtti) in global settings, and your project will compile.









No comments:

Post a Comment