How do I get this minimal LVGL example to work? (Latest version, v9.2?)

Hi there,

Before I give up on LVGL, I’ll try to describe my test of a minimal app using the examples.

I am running this code in Windows+CodeBlocks whithout a problem:

/**
 * @file main
 *
 */

/*********************
 *      INCLUDES
 *********************/
#include <stdlib.h>
#include <unistd.h>

#include "lvgl/lvgl.h"
#include "lvgl/demos/lv_demos.h"

/*********************
 *      DEFINES
 *********************/

/**********************
 *      TYPEDEFS
 **********************/

/**********************
 *  STATIC PROTOTYPES
 **********************/

/**********************
 *  STATIC VARIABLES
 **********************/
static const wchar_t * title = L"LVGL port Windows CodeBlocks.      https://lvgl.io | https://docs.lvgl.io";

/**********************
 *      MACROS
 **********************/

/**********************
 *   GLOBAL FUNCTIONS
 **********************/
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR szCmdLine, int nCmdShow)
{
    /*Initialize LVGL*/
    lv_init();

    /*Initialize the HAL for LVGL*/
    lv_display_t * display = lv_windows_create_display(title, 800, 480, 100, FALSE, FALSE);
    lv_windows_acquire_pointer_indev(display);

    /*Output prompt information to the console, you can also use printf() to print directly*/
    LV_LOG_USER("LVGL initialization completed!");

    /*Run the demo*/
    lv_demo_widgets();
    char * demo_str[] = {"widgets"};
    lv_demos_create(demo_str, strlen((char * )demo_str));

    while(1) {
        /* Periodically call the lv_task handler.
         * It could be done in a timer interrupt or an OS task too.*/
        lv_task_handler();
        usleep(5000);       /*Just to let the system breath*/
    }
    return 0;
}

Now I move to a Raspberry Pi. I change a bit the main function’s code, so that it has a chance to run in the new host (no changes to the include statements):

int main(void)
{
    /*Initialize LVGL*/
    lv_init();

    /*Initialize the HAL for LVGL*/
    lv_display_t * display = lv_display_create(800, 400);
    //lv_windows_acquire_pointer_indev(display);

    /*Output prompt information to the console, you can also use printf() to print directly*/
    //LV_LOG_USER("LVGL initialization completed!");

    //*Run the demo*/
    lv_demo_widgets();
    char * demo_str[] = {"widgets"};
    lv_demos_create(demo_str, strlen((char * )demo_str));

    while(1) {
        /* Periodically call the lv_task handler.
         * It could be done in a timer interrupt or an OS task too.*/
        lv_task_handler();
        usleep(5000);       /*Just to let the system breath*/
    }
    return 0;
}

Unfortunately I obtain errors when trying to compile with gcc:

/usr/bin/ld: /tmp/ccQMzRXQ.o: in function `lv_task_handler':
main.c:(.text+0x8): undefined reference to `lv_timer_handler'
/usr/bin/ld: /tmp/ccQMzRXQ.o: in function `main':
main.c:(.text+0x1c): undefined reference to `lv_init'
/usr/bin/ld: main.c:(.text+0x28): undefined reference to `lv_display_create'
/usr/bin/ld: main.c:(.text+0x30): undefined reference to `lv_demo_widgets'
/usr/bin/ld: main.c:(.text+0x50): undefined reference to `lv_demos_create'
collect2: error: ld returned 1 exit status

Any idea of why I am having these problems in the RasPi?
For example, “lv_demos_create” is declared in “lvgl\demos\lv_demos.h”, which I have included, but still the compiler complains about it!

Thanks in advance.

(apologies for the bad formatting, I don’t know how to improve it)

Hello,

What does your file structure look like?
Are you sure you are actually compiling the source for LVGL along with your project?
Did you set your "lv_conf.h correctly?

This hardly seems like an issue with LVGL directly, rather something with the way your project is set up. It is quite strange to me that lv_display_create and lv_task_handler() do not give errors but all other LVGL functions do. Wish I knew exactly what was going on here.

Kind regards

Hello Tinus,

The structure of the project is very simple: main.c, and the folder with lvgl! Just like it says in the help!

No idea what’s going on.