How to change the compiler options for a single file?


Doing some experimentation with the link time optimization (-flto, --lto), I reached a point where I want to change the compile options for some unrelated files.

How does one change the compile options for single files in mbed Studio?

Thanks & regards.


I’ve done some digging and unfortunately the mbed-os build tools used by Mbed Studio don’t support this. Mbed Studio uses the Mbed CLI 1 tools as documented here:

If you really need per-file flags, you might make progress by switching to the Mbed CLI 2 tools and use CMake to build:
Then modify one of the CMakeLists.txt files to include your flags. You would need to run the mbed CLI build from the terminal rather than with Studio’s built-in build button for this.

Kind regards,

1 Like