记录一下ubuntu linux搭建 lvgl的过程
本地环境:ubuntu 16.04
ubuntu + lvgl + sdl2
1 获取源码
c
git clone https://github.com/lvgl/lv_port_linux.git
cd lv_port_linux/
git submodule update --init --recursive
查看分支:
git branch -a
我选择的是9.2(master分支一直在变动,可能不安全,我们需要一个稳定的版本)
git checkout remotes/origin/release/v9.2 -b v92
git branch -a
为了保险起见,切完分支后,更新下子模块.
git submodule update --init --recursive
2 改 lv_conf.h
lv_conf.h文件就在根目录下.
修改下面三个宏,需要将LV_USE_LINUX_FBDEV => 0 SDL=>1
c
#define LV_USE_LINUX_FBDEV 0
#define LV_USE_LINUX_DRM 0
#define LV_USE_SDL 1
953: LV_SDL_BUF_COUNT 2
3 编译
c
mkdir build
cd build
cmake ..
make -j
问题1 :cmake版本过低,没有办法,自己去升级一下.
cmake版本升级方法
继续:
问题2 :cmake 报错 缺少sdl模块,安装一下:
sudo apt-get update && sudo apt-get install -y build-essential libsdl2-dev
最后还有问题 :
FindSDL2_image 模块找不到
CMake Error at CMakeLists.txt:13 (add_executable): Target "main" links to item "-L/usr/lib/x86_64-linux-gnu -lSDL2 " which has leading or trailing whitespace. This is now an error according to policy CMP0004.
安装一下吧:
sudo apt-get install libsdl2-image-dev
但是安装之后还是报错.
原因 : 因为sdl2安装包里面有cmake,但是sdl2_iamge木有cmake,就导致SDL2_image找不到.
解决:修改CMakeLists.txt(根目录下的).
将find_package(SDL2_image)替换为下面两行
c
find_library(NAME SDL2_image REQUIRED)
link_libraries(SDL2_image)
没完了 : 还有错误:
CMake Error at CMakeLists.txt:13 (add_executable): Target "main" links to item "-L/usr/lib/x86_64-linux-gnu -lSDL2 " which has leading or trailing whitespace. This is now an error according to policy CMP0004.
这是因为"-L/usr/lib/x86_64-linux-gnu -lSDL2 ",-lSDL2后面多了一个空格.
解决:修改CMakeLists.txt
在target_link_libraries之前,set(SDL2_LIBRARIES "-L${SDL2_LIBDIR} -lSDL2")
c
set(SDL2_LIBRARIES "-L${SDL2_LIBDIR} -lSDL2")
target_link_libraries(main lvgl lvgl::examples lvgl::demos lvgl::thorvg ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES} ${Libdrm_LIBRARIES} m pthread)
继续编译:
make -j
又有问题 :
lv_sdl_window.c:413:5: error: unknown type name 'SDL_PixelFormatEnum'
修改文件lv_sdl_window.c:413左右.
我们不选了,直接用SDL_PIXELFORMAT_RGB888
c
/*
#if LV_COLOR_DEPTH == 32
SDL_PixelFormatEnum px_format =
SDL_PIXELFORMAT_RGB888; //same as SDL_PIXELFORMAT_RGB888, but it's not supported in older versions
#elif LV_COLOR_DEPTH == 24
SDL_PixelFormatEnum px_format = SDL_PIXELFORMAT_BGR24;
#elif LV_COLOR_DEPTH == 16
SDL_PixelFormatEnum px_format = SDL_PIXELFORMAT_RGB565;
#else
#error("Unsupported color format")
#endif
// px_format = SDL_PIXELFORMAT_BGR24;
*/
dsc->texture = SDL_CreateTexture(dsc->renderer, SDL_PIXELFORMAT_RGB888,
SDL_TEXTUREACCESS_STATIC, disp->hor_res, disp->ver_res);
SDL_SetTextureBlendMode(dsc->texture, SDL_BLENDMODE_BLEND);
}
继续 make -j
又来问题 :
lv_sdl_window.c:(.text+0x272):对'SDL_SetWindowResizable'未定义的引用
通过查代码发现,lv_sdl_window_set_resizeable木有人调用,所以直接将这一行注释掉.
c
void lv_sdl_window_set_resizeable(lv_display_t * disp, bool value)
{
lv_sdl_window_t * dsc = lv_display_get_driver_data(disp);
//SDL_SetWindowResizable(dsc->window, value);
}
继续 make -j
我这里就成功了哈.
运行main
cd ../bin
./main
4 修改main.c
注释原来的demo,现在测试lv_demo_music.
其他例子:lv_demo_xxx也行.
//lv_demo_widgets();
//lv_demo_widgets_start_slideshow();
c
int main(void)
{
lv_init();
/*Linux display device init*/
lv_linux_disp_init();
/*Create a Demo*/
//lv_demo_widgets();
//lv_demo_widgets_start_slideshow();
lv_demo_music();//测试music
/*Handle LVGL tasks*/
while(1) {
lv_timer_handler();
usleep(5000);
}
return 0;
}
问题 :
鼠标点击没反应.
解决:
在lv_port_linux\lvgl\src\drivers\sdl\lv_sdl_window.c
lv_sdl_window_create() 135行:添加lv_sdl_mouse_create();
ok: