Use lvgl with C++


I am going to use LVGL with C++.
During the compilation I face some issues with the include files.

  1. lv_types.h
    When it is included in C++ file, STDC_VERSION is not defined and evaluates to 0.
    "This macro is not defined if the -traditional-cpp option is used, nor when compiling C++ or Objective-C. "

  2. lv_color.h

static lv_color_t fg_color_save = {.full = 0};
static lv_color_t bg_color_save = {.full = 0};
static lv_color_t res_color_saved = {.full = 0};

Designated initializers are only available since c++20

Could header files be made more friendly to c++ inclusion?

Best regards.

I’ve applied a patch that hopefully fixes 1.

For 2, since these are static variables inside a function, they should be initialized to 0 automatically, and the initializer should not be necessary. Can you remove it and confirm that it works?

Thank you!

The patch fixes 1.

As for 2 there is one more line with designated initializers
#define LV_COLOR_MAKE(r8, g8, b8) (_LV_COLOR_MAKE_TYPE_HELPER{.full = (uint8_t)((b8 >> 7) | (g8 >> 7) | (r8 >> 7))})

Are you using C++11 or newer? There are some helper macros to prevent issues.

The link doesn’t work.
I’m using c++14.

Sorry about that; I usually double-check my links but somehow I pasted that one incorrectly.

I’ve opened an issue on GitHub so @kisvegabor can take a look. Let’s see what he says.

We’ve applied a fix to master which should address the designated initializer issue.

Thank you!

@Alexander which compiler you use?
I have make some fixes for MSVC C++14 compiler: