环境说明
- windows (win10)
- clion (CLion 2025.2.4)
- LVGL (2025-12-20 master 最新)
- SDL2 lib (
release-2.32.8手动编译) - x86_64-w64-mingw32 编译工具链
编译 SDL2 lib
配置 clion cmake
-
SDL2 lib 以静态库的方式链接到工程
-
LVGL 的配置文件
lv_conf.h配置#define LV_USE_SDL 1,也就是使能LV_USE_SDL -
工程
CMakeLists.txt中增加如下配置
c
link_directories(libs/sdl/lib)
include_directories(libs/sdl/include)
target_link_libraries(lvgl-sim
libSDL2.a
imm32
winmm
SetupAPI
Version)
windows SDL 驱动
c
static lv_display_t *display;
static lv_indev_t *mouse;
static lv_indev_t *mouse_wheel;
static lv_indev_t *keyboard;
int hal_init_sdl(void)
{
display = lv_sdl_window_create(LCD_WIDTH, LCD_HEIGHT);
if (!display)
{
return -1;
}
mouse = lv_sdl_mouse_create();
if (!mouse)
{
return -1;
}
mouse_wheel = lv_sdl_mousewheel_create();
if (!mouse_wheel)
{
return -1;
}
keyboard = lv_sdl_keyboard_create();
if (!keyboard)
{
return -1;
}
return 0;
}
显示效果
- 可以正常的显示

说明
- 其实在 windows 端,显示可以不使用 SDL2,而是使用 LVGL 的 windows 的驱动,比如
lv_windows_get_display_window_handle