LVGL 시뮬레이터를 Ubuntu에 설치하는 방법

lvgl

LVGL은 RTOS에서 사용할 수 있는 그래픽 라이브러리이고, GPU가 없어도 동작한닥고 한다. 다양한 환경에서 시뮬레이터를 설치해서 LVGL 코드를 실행해볼 수 있다. 웹에서 플레이그라운드도 제공하는데, 파이썬 코드라서, 난 C++ 코드로 돌려보고 싶어서 시뮬레이터를 설치하였다.

먼저 다양한 환경과 에디터를 제공하는데, 그 중에서 나는 Ubuntu에 VScode 프로젝트를 설치하였다.

1. 준비 환경

Ubuntu에서 LVGL 공식 시뮬레이터는 SDL2를 활용한 lv_sim_vscode_sdl 프로젝트를 Visual Studio Code로 띄워 빌드하는 방식입니다. VSCode가 설치되어 있어야 하며, GUI 환경에서 SDL 렌더링을 띄울 수 있어야 합니다. WSL2에서 작업할 경우에는 XLuanch/terminater로 VSCode를 WSL에 연결한 뒤 동일한 흐름으로 진행하면 됩니다.

2. 필수 패키지 설치

패키지 목록을 업데이트하고 빌드에 필요한 도구와 SDL2를 깔아둡니다.

  • build-essentiallibsdl2-dev는 C 컴파일과 SDL 출력에 필요한 라이브러리를 제공합니다.
sudo apt-get update
sudo apt-get install -y build-essential libsdl2-dev git cmake

3. 시뮬레이터 소스 가져오기

다음 명령어로 레포지토리를 클론하고 --recursive 옵션으로 서브모듈까지 가져옵니다.

git clone --recursive https://github.com/lvgl/lv_sim_vscode_sdl

4. 빌드하고 실행하기

  1. VSCode의 main/src/main.c를 열고, F5를 눌러 시뮬레이터를 빌드합니다. 빌드가 끝나면 ./bin/main 실행 파일이 생성됩니다.
  2. 생성된 바이너리를 직접 실행하려면 터미널에서 ./bin/main를 입력하면 SDL 창이 뜹니다.

또는 터미널에서 아래와 같이 빌드 명령어를 입력하여 빌드할 수도 있습니다.

mkdir build
cd build
cmake ..
cmake --build .

Project root에서는 아래 명령어로 빌드 가능.

cmake -S . -B build
cmake --build build

cmake에서 sdl 에러가 발생하면 아래 패키지를 설치하세요. sudo apt-get install libsdl2-dev

5. 실행

실행은 루트 디렉토리에서 아래와 같이 합니다.

./bin/main
시뮬레이터 실행
시뮬레이터 실행

6. 주의사항

  • WSL2에서도 동일한 폴더를 VSCode로 열고 F5를 누르면 됩니다. XLuanch와 terminater를 통해 WSL 세션을 연 뒤 위 단계를 그대로 따라가면 네이티브 Ubuntu와 같은 결과를 얻을 수 있습니다.
  • SDL 창이 뜨지 않거나 입력이 먹히지 않으면 SDL2가 제대로 설치 되었는지 확인하세요.

cmake에서 sdl 에러 발생 시 libsdl2-dev 설치 필요:

lv_sim_vscode_sdl/build$ cmake ..
-- The C compiler identification is GNU 13.3.0
-- The CXX compiler identification is GNU 13.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- FreeRTOS is disabled
CMake Error at CMakeLists.txt:60 (find_package):
  By not providing "FindSDL2.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "SDL2", but
  CMake did not find one.

  Could not find a package configuration file provided by "SDL2" with any of
  the following names:

    SDL2Config.cmake
    sdl2-config.cmake

  Add the installation prefix of "SDL2" to CMAKE_PREFIX_PATH or set
  "SDL2_DIR" to a directory containing one of the above files.  If "SDL2"
  provides a separate development package or SDK, be sure it has been
  installed.

Related Posts