How to change the compiler options for a single file?

Hi,

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.

Hi,

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:
https://os.mbed.com/docs/mbed-os/v6.15/build-tools/compile.html

If you really need per-file flags, you might make progress by switching to the Mbed CLI 2 tools and use CMake to build:
https://os.mbed.com/docs/mbed-os/v6.15/build-tools/use.html
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,
Matthew

1 Like