lvgl / lv_port_linux

LVGL configured to work with a standard Linux framebuffer
MIT License
260 stars 160 forks source link

SDL2 does not work #57

Open zxslzx opened 2 months ago

zxslzx commented 2 months ago

I tested under debian12, error occurred during startup, Segmentation fault.

kisvegabor commented 2 months ago

Please share your lv_conf.h and main.c. How did you compile the project?

biglion1990 commented 3 weeks ago

[main] Building folder: /home/ubuntu/Desktop/lvgl/build [build] Starting build [proc] Executing command: /usr/bin/cmake --build /home/ubuntu/Desktop/lvgl/build --config Debug --target all -j 10 -- [build] [ 45%] Built target lvgl [build] [ 52%] Built target lvgl_thorvg [build] [ 69%] Built target lvgl_demos [build] [ 99%] Built target lvgl_examples [build] [100%] Linking CXX executable ../bin/lvglsim [build] /usr/bin/ld: lib/liblvgl.a(lv_sdl_window.c.o): in function lv_sdl_window_create': [build] /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:86: undefined reference toSDL_Init' [build] /usr/bin/ld: /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:87: undefined reference to SDL_StartTextInput' [build] /usr/bin/ld: /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:89: undefined reference toSDL_GetTicks' [build] /usr/bin/ld: lib/liblvgl.a(lv_sdl_window.c.o): in function lv_sdl_window_set_resizeable': [build] /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:144: undefined reference toSDL_SetWindowResizable' [build] /usr/bin/ld: lib/liblvgl.a(lv_sdl_window.c.o): in function lv_sdl_get_disp_from_win_id': [build] /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:168: undefined reference toSDL_GetWindowID' [build] /usr/bin/ld: lib/liblvgl.a(lv_sdl_window.c.o): in function lv_sdl_window_set_title': [build] /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:179: undefined reference toSDL_SetWindowTitle' [build] /usr/bin/ld: lib/liblvgl.a(lv_sdl_window.c.o): in function lv_sdl_quit': [build] /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:191: undefined reference toSDL_Quit' [build] /usr/bin/ld: lib/liblvgl.a(lv_sdl_window.c.o): in function sdl_event_handler': [build] /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:303: undefined reference toSDL_Quit' [build] /usr/bin/ld: /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:271: undefined reference to SDL_PollEvent' [build] /usr/bin/ld: lib/liblvgl.a(lv_sdl_window.c.o): in functionwindow_create': [build] /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:325: undefined reference to SDL_CreateWindow' [build] /usr/bin/ld: /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:329: undefined reference toSDL_CreateRenderer' [build] /usr/bin/ld: /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:341: undefined reference to SDL_SetWindowSize' [build] /usr/bin/ld: lib/liblvgl.a(lv_sdl_window.c.o): in functionwindow_update': [build] /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:353: undefined reference to SDL_UpdateTexture' [build] /usr/bin/ld: /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:355: undefined reference toSDL_RenderClear' [build] /usr/bin/ld: /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:358: undefined reference to SDL_RenderCopy' [build] /usr/bin/ld: /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:360: undefined reference toSDL_RenderPresent' [build] /usr/bin/ld: lib/liblvgl.a(lv_sdl_window.c.o): in function texture_resize': [build] /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:382: undefined reference toSDL_DestroyTexture' [build] /usr/bin/ld: /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:396: undefined reference to SDL_CreateTexture' [build] /usr/bin/ld: /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:398: undefined reference toSDL_SetTextureBlendMode' [build] /usr/bin/ld: lib/liblvgl.a(lv_sdl_window.c.o): in function res_chg_event_cb': [build] /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:435: undefined reference toSDL_SetWindowSize' [build] /usr/bin/ld: lib/liblvgl.a(lv_sdl_window.c.o): in function release_disp_cb': [build] /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:453: undefined reference toSDL_DestroyTexture' [build] /usr/bin/ld: /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:455: undefined reference to SDL_DestroyRenderer' [build] /usr/bin/ld: /home/ubuntu/Desktop/lvgl/lvgl/src/drivers/sdl/lv_sdl_window.c:456: undefined reference toSDL_DestroyWindow' [build] collect2: error: ld returned 1 exit status [build] make[2]: [CMakeFiles/lvglsim.dir/build.make:104: ../bin/lvglsim] Error 1 [build] make[1]: [CMakeFiles/Makefile2:133: CMakeFiles/lvglsim.dir/all] Error 2 [build] make: *** [Makefile:130: all] Error 2 [proc] The command: /usr/bin/cmake --build /home/ubuntu/Desktop/lvgl/build --config Debug --target all -j 10 -- exited with code: 2 [driver] Build completed: 00:00:01.089 [build] Build finished with exit code 2

I tested under ubuntu20.04 , installed SDL2, error。

kisvegabor commented 3 weeks ago

Have you installed SDL like this:

sudo apt-get install libsdl2-dev 
biglion1990 commented 2 weeks ago

I removed the if().... .elseif()... .endif. and it works!

cmake_minimum_required(VERSION 3.10)
project(lvgl)

#Uncomment if the program needs debugging
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -ggdb")

set(CMAKE_C_STANDARD 99) # LVGL officially supports C99 and above
set(CMAKE_CXX_STANDARD 17) #C17
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
add_subdirectory(lvgl)
target_include_directories(lvgl PUBLIC ${PROJECT_SOURCE_DIR})

find_package(PkgConfig REQUIRED)
pkg_check_modules(SDL2 REQUIRED sdl2)
pkg_check_modules(SDL2_image REQUIRED SDL2_image)

target_include_directories(lvgl PRIVATE ${SDL2_INCLUDE_DIRS})
target_include_directories(lvgl PRIVATE ${SDL2_IMAGE_INCLUDE_DIRS})
add_executable(lvglsim main.c mouse_cursor_icon.c)
target_link_libraries(lvglsim lvgl lvgl::examples lvgl::demos lvgl::thorvg ${SDL2_LIBRARIES} ${SDL2_IMAGE_LIBRARIES} m pthread)

add_custom_target (run COMMAND ${EXECUTABLE_OUTPUT_PATH}/lvglsim DEPENDS lvglsim)
kisvegabor commented 2 weeks ago

I've just tried it out and could reproduce the issue. You should call CMake like this: cmake -DLV_USE_SDL=1 ...

It's something that we really should document. There is also an LVGL issue to make CMake handling more unified. @etag4048 will work on it soon.