# Code::Block LVGL on Windows

## Code::Block

[Binary releases - Code::Blocks](https://www.codeblocks.org/downloads/binaries/#imagesoswindows48pnglogo-microsoft-windows)

Download [codeblocks-20.03mingw-setup.exe](https://www.fosshub.com/Code-Blocks.html?dwl=codeblocks-20.03mingw-setup.exe)

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729668988320/fa94a906-7f03-4f5e-b503-229d4a617dcb.png align="center")

### Create Empty Project

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729669028958/37a20309-7a66-4bb9-ac82-2b9f30eb1dff.png align="center")

## LVGL

```bash
cd CodeBlock_LVGL
git clone https://github.com/lvgl/lvgl.git
cp lvgl/lv_conf_template.h lv_conf.h
```

Right click `CodeBlock_LVGL` Project → `Add files recursively…`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729669930812/238a14e5-7130-430b-916a-836bcb430628.png align="center")

Choose `lvgl`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729670045835/82d4ba0a-7936-4281-af29-ef2ead54c2c7.png align="center")

Click `OK`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729670107636/4d322271-d6a5-45f0-8451-c22fb74f0a28.png align="center")

Right click `CodeBlock_LVGL` Project → `Add files...`

Choose `lv_conf.h`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729670224601/957e1b13-e6e0-44c5-be0d-971f073c34e2.png align="center")

Open `lv_conf.h` and change the `#if 0` at the beginning to `#if 1` to enable its content.

```c
#if 1 /* Set this to "1" to enable content */
#define LV_USE_OS   LV_OS_WINDOWS
/** LVGL Windows backend */
#define LV_USE_WINDOWS    1
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729670338297/ccfb5268-907c-481e-a228-f25dd0d31517.png align="center")

`Remove Files…` `Sources/tests` and `Headers/tests`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729670499798/4fbed642-49bf-47e1-ade3-884cf32d43fa.png align="center")

`Project → Build Options…`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729670939524/fd05da69-db79-469b-8e39-0432be45d5fd.png align="center")

CodeBlock\_LVGL → Compiler settings → Compiler flags → `-std=c++17`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729670976585/b9306b08-6ca4-421f-bcf0-7eb0c1f853c9.png align="center")

CodeBlock\_LVGL → Compiler settings → #defines

```bash
WINVER=0x0601
WIN32
_WIN32
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729671384791/4a74dcb5-154a-4ec9-a191-8c9e8b4506ad.png align="center")

CodeBlock\_LVGL → Linker settings → Link Libraries:

```bash
mingw32
```

CodeBlock\_LVGL → Linker settings → Other linker options:

```bash
-lmingw32 -mwindows -mconsole
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729671654853/5dad558d-e610-45bc-a234-2aec175ae3b5.png align="center")

CodeBlock\_LVGL → Search directories `. lvgl`

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729671161384/6f2812df-bd69-4715-89ac-24122d1ca42b.png align="center")

Properties →

###   
Souce code

```c
#include <stdlib.h>
#include <unistd.h>

#include "lvgl/lvgl.h"

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

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!");


    lv_obj_t * label = lv_label_create(lv_screen_active());

    // Set the label text
    lv_label_set_text(label, "Hello, LVGL!");

    // Align the label in the center
    lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);

    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;
}
```

![](https://cdn.hashnode.com/res/hashnode/image/upload/v1729678938626/7d7c6393-b2c9-4909-a706-8aebf34586e9.png align="center")

## Source Code

[jiaxianhua/CodeBlock\_LVGL](https://github.com/jiaxianhua/CodeBlock_LVGL)
