Many compiler warnings of type -Wdiscarded-qualifiers

What do you want to achieve?

I want to compile the program without getting any warning (or error) messages

What have you tried so far?

created a program (which does work) with many lv_set_… calls, and on many of them I get a warning from the compiler

Screenshot or video

  lv_slider_set_value(ui_camexps, 1, LV_ANIM_OFF);
 

The compiler spits out

lib/ui/ui.c: In function 'ui_event_camexps':
lib/ui/ui.c:229:55: warning: passing argument 3 of '_ui_slider_set_text_value' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
         _ui_slider_set_text_value(ui_camexpn, target, "", "");
                                                       ^~
In file included from lib/ui/ui.c:7:
lib/ui/ui_helpers.h:108:71: note: expected 'char *' but argument is of type 'const char *'
 void _ui_slider_set_text_value(lv_obj_t * trg, lv_obj_t * src, char * prefix, char * postfix);
                                                                ~~~~~~~^~~~~~
lib/ui/ui.c:229:59: warning: passing argument 4 of '_ui_slider_set_text_value' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
         _ui_slider_set_text_value(ui_camexpn, target, "", "");
                                                           ^~

Others

  • SquareLine Studio version: 1.2.2
  • Operating system: win 11 pro
  • Target hardware: ESP32

With best regards

Volker

Thank you for reporting it. We will look into it.

1 Like

FYI, this is using PlatformIo with the Arduino framework. The warning cannot be disabled with a compiler setting, as -Wnp-discarded-qualifiers is not allowed with a C++ compiler….

With best regards

Volker

I have same issue in lvgl lib 7 warnings

Compiling .pio\build\esp32s3mykorvo\lib8f9\lvgl\core\lv_obj_tree.c.o
.pio/libdeps/esp32s3mykorvo/lvgl/src/core/lv_obj.c: In function 'lv_init':
.pio/libdeps/esp32s3mykorvo/lvgl/src/core/lv_obj.c:143:18: warning: initialization discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
     char * txt = "Á";
                  ^~~~
Compiling .pio\build\esp32s3mykorvo\lib8f9\lvgl\core\lv_refr.c.o

And too many strings in my code is marked with this warning.
Seems as platformio issue
You can suppress in ini set py scripts
and create file

Import("env")

# General options that are passed to the C and C++ compilers
#env.Append(CCFLAGS=["flag1", "flag2"])

# General options that are passed to the C compiler (C only; not C++).
env.Append(CFLAGS=["-Wno-discarded-qualifiers"])

# General options that are passed to the C++ compiler
#env.Append(CXXFLAGS=["flag1", "flag2"])
1 Like

Yes, I have experienced this with the latest version today. The previous version that I was using did not seem to have it. After writing custom functions, for some reason I cant access them in the events.c file either. :confused:

Thanks for your feedback. Unfortunately, the extra_scripts workaround does not work around the issue :). The extra script is named in the platformio.ini, it is invoked (as verified by an print statement), but to no avail, the gazillion warnings still get issued.

Anyhow, suppressing warnings is not the “right thing to do” ™. There should be no warning messages in the first place.

With best regards

Volker

In ini is requred line extra_scripts = pre:extra_script.py
documented example stupidly omit this info

It will be fixed in the next release. I hope it will be tomorrow (Monday).

@vbandke +1
Is this solved? I still have this issue in v8.3.7.

image

It’s a different issue and it’s being discussed here: fix: Explicit casts to avoid -Wdiscarded-qualifiers warnings by nebkat · Pull Request #4326 · lvgl/lvgl · GitHub