I need dynamic casts for my project, I'm getting:
error: 'dynamic_cast' not permitted with -fno-rtti
It appears that RTTI (run-time type information) is disabled with the fno-rtti
compiler flag.
How do I change this?
Arduino Stack Exchange is a question and answer site for developers of open-source hardware and software that is compatible with Arduino. It only takes a minute to sign up.
Sign up to join this communityI need dynamic casts for my project, I'm getting:
error: 'dynamic_cast' not permitted with -fno-rtti
It appears that RTTI (run-time type information) is disabled with the fno-rtti
compiler flag.
How do I change this?
It apparently is true that “RTTI (run-time type information) is disabled with the fno-rtti
compiler flag”; however, looking at compiler.c.flags
and compiler.cpp.flags
in platform.txt
, no fno-rtti
compiler flag is set, suggesting that gcc sets it by default.
One way to turn off fno-rtti
is adding a -frtti
flag into the appropriate flags string in platform.txt
. As a side effect, this will affect all sketches subsequently compiled, rather than only those that need dynamic casts.
Note, on a microcontroller, a more-appropriate way to deal with the problem is getting rid of the need for dynamic casts, via function overloading.
Edit 1: On Linux, typical file paths to platform.txt
are like /opt/arduino-1.6.3/hardware/arduino/avr/platform.txt
or /opt/arduino-1.8.0/hardware/arduino/avr/platform.txt
. I don't know the location on OSX. However, a command like locate *avr/platform.txt
should reveal its location. (If locate
is a new install on your system, first run updatedb
, which may take a while.)