vpaeder / lvglpp

A C++ wrapper for LVGL
MIT License
33 stars 11 forks source link

Build failed in PlarformIO #1

Open redstonee opened 6 months ago

redstonee commented 6 months ago

Hello! I'm trying to use lvglpp in a Platform IO project. When I start building it, errors occurs like below:

lib/lvglpp/src/lvglpp/widgets/switch/switch.cpp:12:5: error: specializing member 'lvgl::core::Widget<lv_switch_create>::Switch' requires 'template<>' syntax
     Switch::Switch() {
     ^~~~~~
lib/lvglpp/src/lvglpp/widgets/switch/switch.cpp:16:5: error: specializing member 'lvgl::core::Widget<lv_switch_create>::Switch' requires 'template<>' syntax
     Switch::Switch(Object & parent) {
     ^~~~~~
lib/lvglpp/src/lvglpp/widgets/switch/switch.cpp:20:10: error: specializing member 'lvgl::core::Widget<lv_switch_create>::initialize' requires 'template<>' syntax
     void Switch::initialize() {
          ^~~~~~
lib/lvglpp/src/lvglpp/widgets/switch/switch.cpp:23:10: error: specializing member 'lvgl::core::Widget<lv_switch_create>::initialize' requires 'template<>' syntax
     void Switch::initialize(Object & parent) {
          ^~~~~~
*** [.pio\build\esp32-s3-devkitc-1\libee7\lvglpp\lvglpp\widgets\switch\switch.cpp.o] Error 1

The platform is esp32-s3, and the C++ standard is set to gnu++2a.
Thank you!

vpaeder commented 6 months ago

Hi! I guess clang is less restrictive there as I doesn't complain. The Switch class is a specialization of the Widget class. Try to add ´template<>´ in front of the offending lines and see what happens. If that doesn't fix it I'll see to write it by the standards, but that might take some time.

redstonee commented 6 months ago

Thanks very much for your reply!
I tried to rewrite the Switch class with a more complicated way as below:

class Switch : public Widget<lv_switch_create> {
    void initialize();
    void initialize(Object &parent);

  public:
    using Widget::Widget;
};

And removed the constructors in switch.cpp then it works.
Besides, there are some dynamic_pointer_cast in anim.cpp, which requires RTTI feature. However if -fno-rtti is removed when building the project for ESP32, linking errors occured. Then I replaced them with static_pointer_cast, which made it able to build. But when an animation is configured, my ESP32 crashed with this info:

assert failed: void lvgl::misc::Animation::set_path_cb(lv_anim_path_cb_t) anim.cpp:60 (this != this->raw_ptr()->var)

Now I have no idea how to fix it. :(

vpaeder commented 5 months ago

Well, you're just subclassing a template class, which is fine but this shouldn't be necessary. For the dynamic cast thing, I can't say if I don't know what the linking errors are. With static cast you're removing a runtime check, but if you know how to keep your code safe that way go ahead. The assert fails when you used Animation.set_var or any of the callback setters in template form and you try to use one callback setter in non-template form. You would replace the pointer to the callbacks stored in the C structure and make some previously-defined callbacks to fail. Post the bit of code where you define the animation object and callbacks and we can see what should be amended.