1

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?

1

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.)

  • Do you know where the platform.txt file is on OS X? Perfect answer, thanks! – Cody Smith Apr 24 '17 at 21:42
  • @CodySmith, see Edit 1 – James Waldby - jwpat7 Apr 24 '17 at 21:52
  • This does not entirely solve the problem for those wishing to use rtti. This does not enable the linker to complete the compile of a simple sketch with dynamic_cast in it. What are the steps to get that aspect working. (I know there are people who say it shouldn’t be done, but I’m curious and have some ideas I’d like to test). I have drawn a blank as to how to complete this process. (Sorry this should have been a comment) <windows dev platform> – Simon Feb 26 '18 at 17:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.