How to fix LVGL undefined reference to 'lv_log_register_print_cb'

Problem

While compiling your LVGL/Adafruit based application, you see a linker error message such as

Linking .pio/build/esp32dev/firmware.elf
/home/uli/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32dev/lib67d/libAdafruit LittlevGL Glue Library.a(Adafruit_LvGL_Glue.cpp.o):(.literal._ZN18Adafruit_LvGL_Glue5beginEP15Adafruit_SPITFTPvb+0x44): undefined reference to `lv_log_register_print_cb'
/home/uli/.platformio/packages/toolchain-xtensa-esp32/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld: .pio/build/esp32dev/lib67d/libAdafruit LittlevGL Glue Library.a(Adafruit_LvGL_Glue.cpp.o): in function `Adafruit_LvGL_Glue::begin(Adafruit_SPITFT*, void*, bool)':
/dev/shm/Test/.pio/libdeps/esp32dev/Adafruit LittlevGL Glue Library/Adafruit_LvGL_Glue.cpp:364: undefined reference to `lv_log_register_print_cb'
collect2: error: ld returned 1 exit status
*** [.pio/build/esp32dev/firmware.elf] Error 1

Solution

This error is caused by the Adafruit LVGL binding library using lv_log_register_print_cb, whereas your LVGL log config states to just directly use printf().

Solving it is simple: Just define an empty lv_log_register_print_cb function in your code:

void lv_log_register_print_cb(lv_log_print_g_cb_t print_cb) {
  // Do nothing, not needed here!
}