2022-05-18 6:53 AM - last edited on 2025-03-06 3:00 AM by Andrew Neil
I'm working on a STM32F7 software project with TouchGFX, FreeRTOS, lwIP and more. Now I'm playing with the "cereal" library for serialization which needs the RTTI option enabled. So I unchecked the -fno_rtti option in the compiler/linker options.
But this gives me a lot of linker errors for the TouchGFX code:
ld.exe: [...] undefined reference to `typeinfo for touchgfx::Application' ld.exe: [...] undefined reference to `typeinfo for touchgfx::Container' ld.exe: [...] undefined reference to `typeinfo for touchgfx::Drawable' ld.exe: [...] undefined reference to `typeinfo for touchgfx::Container' ld.exe: [...] undefined reference to `typeinfo for touchgfx::Screen' ld.exe: [...] undefined reference to `typeinfo for touchgfx::TextAreaWithWildcardBase' ld.exe: [...] undefined reference to `typeinfo for touchgfx::Image' ld.exe: [...] undefined reference to `typeinfo for touchgfx::Screen' ld.exe: [...] undefined reference to `typeinfo for touchgfx::DMA_Interface' ld.exe: [...] undefined reference to `typeinfo for touchgfx::AbstractPartition' ld.exe: [...] undefined reference to `typeinfo for touchgfx::AbstractPartition' ld.exe: [...] undefined reference to `typeinfo for touchgfx::AbstractPartition' ld.exe: [...] undefined reference to `typeinfo for touchgfx::HAL'
After a little "research" I think that I would need a TouchGFX lib also compiled with RTTI enabled. Are there any suggestions on how to solve this?
Regards
Tom
2022-05-18 7:48 AM
Hello TDeck.1,
RTTI is not compatible with TouchGFX, that's why you have these messages. The -fno_rtti option must stay checked. I'll ask my colleagues but I don't think we have a solution for that unfortunately. I'll get back to you when I have more infos about it.
/Osman
2025-03-06 1:11 AM
Is there anything new on this issue? Weirdly, IAR compiler just works fine with RTTI activated with the touchgfx library, but not GCC.
2025-03-06 2:15 AM
You can change compiler settings per source file or source folder. So it might work to enable it globally and keep it disabled for TouchGFX.
2025-03-06 2:24 AM
Yes, I know that, but I need RTTI to work for some touchgfx types (Drawable). I just found out the other day, while moving a project from iar to cubeIDE (which uses gcc) that my dynamic_casts to Drawable cause ld linker to complain. No clue how iar could handle it therefore (and everything just worked as supposed) if Osman just stated that RTTI is not compatible with touchgfx?
2025-03-06 2:50 AM
Can you share the code that causes problems?
Perhaps you can avoid typecasting or use static casting. Perhaps you can use std::variant.
2025-03-06 2:57 AM
I have a button library written like that, just a simple example with a DButton:
DVirtualButton touchgfx::Drawable
| |
DAbtsractButton touchgfx::Widget
|-----------------------|
DButton
DButton is both a DVirtualButton and a Drawable. A setup function in a dropDown widget needed to access both DVirtualButton methods (like setOn()) and Drawable methods like setXY(). The setup function was passed a DVirtualButton pointer as argument, which was dynamically casted inside the setup function to a Drawable. I agree it's probably not the best way to do it, but it's an old function, written in c++11 some years ago, when I still didn't understand fully what a dynamic_cast really needed to work out.
I have just quiclkly rewritten the function to avoid using dynamic_cast at all but I'd still be interested to know how to make touchgfx library work with RTTI, and how everything just worked fine with IAR.