PlatformIO Community

Cant remove "-fno-rtti" with pre: script on STM32

I want to use FakeIt for mocking, and run the executable on my board. FakeIt uses typeid() and dynamic casts, and even exceptions, so it won’t compile with the default flags. I don’t want to define these “globally” in platformio.ini, so I’ve decided to use a pre: script to remove/add flags, but I can’t remove “-fno-rtti”.
Here’s what I’ve tried:

Import("env")
if "test" in env.GetBuildType():
  env.Append(CPPDEFINES=["TESTING",]) # not important

  env.ProcessUnFlags(['-fno-rtti',])
  env.ProcessUnFlags('-fno-rtti')
  env['CXXFLAGS'].remove("-fno-rtti")

The first two have no effect, and the last one says, that there is no such item in the list.

When i do build_unflags = ...-fno-rtti in platformio.ini, it works.

I’m not sure if I’m doing something wrong, but as far as I can tell, this should work as intended.

The project can be found on Github

The releavant contents of platformio.ini


extra_scripts = 
  pre:scripts/enable_fpu.py
  pre:scripts/test_add_define.py
  post:scripts/test_port_delay.py

Reminds me of Force RTTI from library? - #23 by cziter15, can you try that, possibly in a post script?

1 Like

Yep, this was working very good after fixes, however now not forcing RTTI in my lib.

Made it a post: script, also upgraded pio to --dev, but still, no luck. I modified my script, and added a env.Dump(), after doing the “remove”. Weird thing is, there is no -fno-rtti in the Dump, but it’s still there while building. I’ve updated the git branch with the changes, and also included an out.txt file, with the output of command: pio test -vvv --environment debug 1> out.txt 2> build_errs.txt. BTW the project should be buildable out of the box, if you are interested in debugging. I can also try to create a minimal version, to reproduce this error.

I’m not familiar with pio scripting, and I’m just gluing stuff together. Should I do env.AddPreAction()?

Here are my changes:

platformio.ini

extra_scripts = 
    post:scripts/test_add_define.py

test_add_define.py

env = DefaultEnvironment()
#Import("projenv")

if "test" in env.GetBuildType():
    env.Append(CPPDEFINES=["TESTING",])
    print("Removing -fnortti -fno-exceptions")
    
    env['CXXFLAGS'].remove("-fno-rtti")
    env.ProcessUnFlags("-fno-rtti")
    
    env['CXXFLAGS'].remove("-fno-exceptions")
    env.ProcessUnFlags("-fno-exceptions")
    env.Append(CXXFLAGS=["--exceptions"])
    print(env.Dump())

Please also take a look at out.txt and build_errs.txt

It’s as if the CXXFLAGS were modified after running the script