Skip to main content
Associate
December 23, 2024
Solved

How to enable C++17 (std::variant) in TouchGFX Simulator

Title: How to enable C++17 (std::variant) in TouchGFX Simulator?

Hello everyone,

I'm working on a TouchGFX project in STM32CubeIDE and trying to use C++17 features in the simulator, specifically `std::variant`. However, when I compile the simulator code, I get the following error:

In file included from gui/include/gui/model/Model.hpp:5:0, from generated/gui_generated/include/gui_generated/common/FrontendApplicationBase.hpp:8, from gui/include/gui/common/FrontendApplication.hpp:4, from generated/gui_generated/include/gui_generated/containers/ItemContainerLevel3Base.hpp:7, from gui/include/gui/containers/ItemContainerLevel3.hpp:4, from gui/src/containers/ItemContainerLevel3.cpp:1: gui/include/gui/common/CommonDefinitions.hpp:257:26: error: 'variant' in namespace 'std' does not name a template type using DataVariant = std::variant<int, float, double, std::string, ConfigData>; ^~~~~~~


It seems that the TouchGFX simulator environment is not compiling with `-std=c++17`. I've tried editing the Makefile in `simulator/gcc/Makefile` and adding `-std=c++17` to `cpp_compiler_options`, but it still fails with the same error.

How can I properly configure TouchGFX (and its built-in MinGW toolchain, if necessary) so that the simulator uses C++17? Is there a specific place to override the default compiler flags? Also, do I need to update the MinGW version that ships with TouchGFX to fully support C++17 features like `std::variant`?

Any advice or steps you can share would be greatly appreciated. Thanks in advance!

This topic has been closed for replies.
josonYeBest answer
Associate
December 23, 2024

In the \TouchGFX\config\gcc\app.mk file, I modified the content as follows:

 

# Relative location of the TouchGFX framework from root of application
touchgfx_path := ../Middlewares/ST/touchgfx

# Location of the TouchGFX Environment
touchgfx_env := ../../../../../../../ProgramFiles/STMicroelectronics/TouchGFX/4.24.1/env
# Optional additional compiler flags
user_cflags := -DUSE_BPP=16 -std=c++17

 

After adding -std=c++17, the build was successful.

1 reply

josonYeAuthorBest answer
Associate
December 23, 2024

In the \TouchGFX\config\gcc\app.mk file, I modified the content as follows:

 

# Relative location of the TouchGFX framework from root of application
touchgfx_path := ../Middlewares/ST/touchgfx

# Location of the TouchGFX Environment
touchgfx_env := ../../../../../../../ProgramFiles/STMicroelectronics/TouchGFX/4.24.1/env
# Optional additional compiler flags
user_cflags := -DUSE_BPP=16 -std=c++17

 

After adding -std=c++17, the build was successful.