Visual Studio 2019 compile errors


I’m trying to use the Visual Studio SDL LVGL Simulator project with the lvgl master from Github.

I get the following error for lv_color.h:482

“Error C4576 a parenthesized type followed by an initializer list is a non-standard explicit type conversion syntax”

The Problem is with the following define:
#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){{(b8 >> 3) & 0x1FU, (g8 >> 2) & 0x3FU, (r8 >> 3) & 0x1FU}})

Is this a bug in LVGL or can I fix this somehow?

I just checked the simulator in Visual Studio, with the master branch (for main and subrepos), and it’s running normally.

Maybe check that you have updated (and checked out) the master branch in all submodules of the project?

Looks like it might an issue with Visual Studio’s C++ support. This feature appears to be unsupported in C++:

It works with GCC C++ compiler. It only throws this error when I’m compiling with VisualStudio. (We are using LVGL functions from C++).

Our G++ Version: gcc version 6.3.1 20170620 (release) [ARM/embedded-6-branch revision 249437] (GNU Tools for ARM Embedded Processors 6-2017-q2-update).

The Error is only with LV_COLOR_MAKE. Maybe if we wrap it in a function so we don’t have it in the header?

I don’t think that will help, because it appears that Visual Studio doesn’t support this syntax at all in C++ mode. We might need to fix that. @kisvegabor?

Is there a way to initialize a struct in a C header file?

E.g. is it working?

#define LV_COLOR_MAKE(r8, g8, b8) ((lv_color_t){ = (b8 >> 3) & 0x1FU, = (g8 >> 2) & 0x3FU, = (r8 >> 3) & 0x1FU})


Thank you for your reply.

Your suggestion does not work with VisualStudio C++ compiler. I’m going to switch to mingw or cygwin gcc/c++ compiler.

If you would like to keep using Visual Studio, I would suggest compiling these files as C files (and not C++ files). The rest of your program can still be C++; you just need to configure the IDE so that it does not treat LittlevGL as a C++ program.

We had previously discussed officially deprecating this mode of compilation (see these comments), because it relies on the assumption that C and C++ are the same language (and they are not). It also adds complexity to our testing as we have to test the code on both a C and C++ compiler.

@kisvegabor I just thought of something. Can the Arduino IDE compile LittlevGL as C source code or does it force C++?


If you include the header lv_color.h in a CPP file then those Macros get compiled with the C++ compiler. Using LVGL with GCC/G++ works 100% but not with the Microsoft C++ compiler. The only issue is with VC++. If you configure The VisualStudio project to use GCC/G++ (MSYS2, Mingw, Cygwin etc) then you can use lv_color.h in C++ code.

Perhaps we should just condition the LV_COLOR_MAKE macro on the code being C and not C++, since it relies on behavior that is only standard in C99 (not C++).

Or we can just remove LV_COLOR_MAKE and use lv_color_make (function) instead. It would prevent to initialize global color variables, but I’m bot sure it’s an issue.

Yep. Just started using lvgl and ran into this issue. Can be fixed with:

#define LV_COLOR_MAKE(r8, g8, b8) lv_color_t({{b8, g8, r8, 0xff}}) /*Fix 0xff alpha*/
1 Like

This looks like a good solution for C++, except that it’s relying on the order of the members. It would be great if members could be assigned by name to help prevent bugs in the future.

As mentioned this is only good for C++.
I ran into this when wanting to create a VS 2017 project from scratch rather than use the lv_sim_visual_studio_sdl repo (in order to understand the moving parts). For anyone doing the same some points to note:

  • Use a console project template
  • Check your target is correct x64 vs x32 and link to the correct version of SDL
  • Change the file with main() in it to be .c. The default is .cpp and this is what caused the issue for me.
1 Like