Before logging an issue, please update to the latest release of Visual Micro from the Downloads Page.

When Logging a Support Issue in the Forum, please ensure you have also:-

  • Enabled vMicro > Compiler > Show Build Properties
  • Re-Compile your program with these settings enabled
 
Save the new Output to a Text File and....
  • Click the Reply button and attach as .txt file OR
  • Click here to Email us with the file attached, and a link to your post
Support requests without the output above may be impossible to answer, so please help us to help you
 
Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic How to set GCC optimizer flags (-O0, -O1, -fno-if-conversion) for ESP32 Arduino projects in Visual S (Read 63 times)
MarcinP
Newbies
*
Offline


Posts: 9
Joined: Aug 29th, 2019
How to set GCC optimizer flags (-O0, -O1, -fno-if-conversion) for ESP32 Arduino projects in Visual S
Sep 2nd, 2026 at 12:22pm
Print Post  
Environment

Visual Studio 2022 / 2025 (Visual Micro)
Board: ESP32-S3 Dev Module (esp32:esp32:esp32s3)
Arduino-ESP32 core: 3.3.7 – 3.3.11 (esp-x32 toolchain 2601)
Host platform in VS: x64 (Debug / Release)
Large C++ project (internet radio), many bundled libraries (AsyncWebServer, audioI2S decoders, etc.)
Problem

I need to control the GCC optimization level and per-file compiler flags for my ESP32-S3 build, but I cannot find a reliable way to do this in Visual Micro.

From the build output, every translation unit is compiled with the core’s default flags, including -Os:

xtensa-esp32s3-elf-g++ ... -Os -Werror=return-type ...
I am hitting intermittent internal compiler errors in the Xtensa GCC toolchain, for example:

internal compiler error: in try_forward_edges, at cfgcleanup.cc
The failing file changes between builds (WebRequest.cpp, Audio.cpp, neaacdec.cpp, mp3_decoder.cpp, celt.cpp, etc.), which suggests a toolchain/optimizer issue, not a syntax error in one source file.

In Arduino IDE / PlatformIO this is usually worked around by adding flags such as:

global: compiler.cpp.extra_flags=-fno-if-conversion
or per-file: lower optimization (-O0 / -O1) on the largest .cpp files
What I have tried

Looked in Visual Micro board / project settings for an “optimization” or “compiler flags” option — nothing obvious that maps to Arduino’s compiler.cpp.extra_flags / build.extra_flags.
Checked whether VS Configuration (Debug vs Release) changes -O — the compile line still shows -Os.
Considered editing the .vcxproj AdditionalOptions, but Visual Micro regenerates Arduino build commands from the board package, so manual MSVC compiler settings do not appear to reach xtensa-esp32s3-elf-g++.
build.extra_flags / upload.extra_flags in board properties appear empty in my .vmps.xml / project metadata.
What I need

A supported way in Visual Micro to:

Set project-wide extra GCC flags (e.g. compiler.cpp.extra_flags=-fno-if-conversion), and/or
Set per-file optimization for selected .cpp files (e.g. Audio.cpp, neaacdec.cpp at -O1 while the rest stays at -Os), and/or
Choose optimization level per VS configuration (Debug = -Og/-O0, Release = -Os/-O2).
Questions

Where is the correct place in Visual Micro to pass Arduino build.flags / compiler.cpp.extra_flags for ESP32?
Is there a platform.local.txt / boards.local.txt workflow that Visual Micro respects when building from VS?
Can per-source-file compiler options be defined in the .vcxproj or a Visual Micro project file without being overwritten?
Is limiting parallel compile jobs the only supported mitigation for GCC ICEs in large ESP32 projects?
Why this matters

Without control over optimizer flags, the only workarounds are retrying the build or downgrading the toolchain — neither is practical for a large, frequently rebuilt project.

Any guidance on the official / supported method would be appreciated.

Thanks.
  

Please Register or Login to the Forum to see File Attachments
Back to top
 
IP Logged
 
Simon@Visual Micro
Administrator
*****
Offline


Posts: 2962
Joined: Feb 13th, 2019
Re: How to set GCC optimizer flags (-O0, -O1, -fno-if-conversion) for ESP32 Arduino projects in Visual S
Reply #1 - Sep 2nd, 2026 at 1:23pm
Print Post  
Thanks for the report, please see below:

Quote:
Where is the correct place in Visual Micro to pass Arduino build.flags / compiler.cpp.extra_flags for ESP32?

Generally these are best placed in the vMicro > Project Properties > Configuration Extra Flags (broken down by all recipes, core, library or project) as your message mentions.

Quote:
Is there a platform.local.txt / boards.local.txt workflow that Visual Micro respects when building from VS?

Yes a local board.txt file can be added to the project (vMicro > Add Code > Add Local Board.txt), which can be used to override any platform or board properties for the project you are working in.  We also support the standard Arduino platform.local.txt and boards.local.txt if they need to be overridden at the board package level, however these are lost each time the project is upgraded and affect all projects consuming that board package.  The project specific board.txt file is often the simplest and avoids the cross project issues and board package update issues.

Quote:
Can per-source-file compiler options be defined in the .vcxproj or a Visual Micro project file without being overwritten?

As above - the local board.txt can be used, or the Project Properties, both remain within the project.

Quote:
Is limiting parallel compile jobs the only supported mitigation for GCC ICEs in large ESP32 projects?

Currently I believe this to be the case, and the standard MSVC compiler options are not consumed in Visual Micro as you have found with your investigation.

Local Board.txt Documentation: https://www.visualmicro.com/page/Local-Project-Boardtxt-Examples.aspx
Project Properties Documentation: https://www.visualmicro.com/page/User-Guide.aspx?doc=Project-Properties-Referenc...

Let me know if I have missed anything, or if you have a further issue with these settings.
  
Back to top
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint