I mainly develop firmware for ARM Cortex M using gcc and I am migrating from C to C++ and even though I am overall happy with the transition, there are some things that I just can't get right.
Currently I am working on a project with FreeRTOS and I am trying to use emio (https://github.com/Viatorus/emio), that is a bit like fmt but a little bit more lightweight.
When I compile the whole project with -O2 or even with -Og stack usage is reasonable, but even though with plain C -Og was good for debugging, with C++ I can't put breakpoints on most templated classes/methods as they are apparently being inlined/optimized, so I have to go down to -O0 to properly debug when needed.
Unfortunately -O0 has quite an issue with emio; any task that uses formatting (that I use for logging) needed like 6K of stack to avoid overflow, whereas higher optimization can be under 1.5K.
Is there any way to make a header only library be compiled with -O2 in all sources that use the library, so I can have good debugging without having to artificially change all stack levels? Or is there any other tip or suggestion on how more seasoned developers work with this kind of issues?
Since there is a sole header file to include, I tried putting a pragma to force all the emio code to have -O2 optimization level, since I probably won't need to debug that, but that does not work as it seems the instantiation of everything inside does not respect the pragma.
The nature of the library makes it nearly impossible to just manually instantiate and use extern template, so I don't know what can be done about this.