fix: can compile in msvc

This commit is contained in:
YobeZhou 2025-05-28 18:11:04 +09:00
parent 9337906544
commit d721bed6aa
2 changed files with 29 additions and 8 deletions

View File

@ -91,11 +91,11 @@ endif()
# Define LVGL configuration as a simple include # Define LVGL configuration as a simple include
target_compile_definitions(main PRIVATE LV_CONF_INCLUDE_SIMPLE) target_compile_definitions(main PRIVATE LV_CONF_INCLUDE_SIMPLE)
target_link_libraries(main lvgl lvgl::examples lvgl::demos lvgl::thorvg ${SDL2_LIBRARIES} m pthread)
# Platform configuration if(MSVC)
if(CMAKE_HOST_WIN32) target_link_libraries(main lvgl lvgl::examples lvgl::demos lvgl::thorvg ${SDL2_LIBRARIES})
target_link_libraries(main -mconsole) else()
target_link_libraries(main lvgl lvgl::examples lvgl::demos lvgl::thorvg ${SDL2_LIBRARIES} m pthread)
endif() endif()
# Only link freertos_config if the FreeRTOS directory exists # Only link freertos_config if the FreeRTOS directory exists
@ -140,6 +140,16 @@ if(LV_USE_FREETYPE)
target_link_libraries(main ${FREETYPE_LIBRARIES}) target_link_libraries(main ${FREETYPE_LIBRARIES})
endif() endif()
# On Windows, GUI applications do not show a console by default,
# which hides log output. This ensures a console is available for logging.
if (WIN32)
if (MSVC)
target_link_options(main PRIVATE "/SUBSYSTEM:CONSOLE")
else()
target_link_options(main PRIVATE "-mconsole")
endif()
endif()
# Apply additional compile options if the build type is Debug # Apply additional compile options if the build type is Debug
if(CMAKE_BUILD_TYPE STREQUAL "Debug") if(CMAKE_BUILD_TYPE STREQUAL "Debug")
message(STATUS "Debug mode enabled") message(STATUS "Debug mode enabled")

View File

@ -7,11 +7,18 @@
/********************* /*********************
* INCLUDES * INCLUDES
*********************/ *********************/
#ifndef _DEFAULT_SOURCE
#define _DEFAULT_SOURCE /* needed for usleep() */ #define _DEFAULT_SOURCE /* needed for usleep() */
#endif
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#ifdef _MSC_VER
#include <Windows.h>
#else
#include <unistd.h> #include <unistd.h>
#include <pthread.h> #include <pthread.h>
#endif
#include "lvgl/lvgl.h" #include "lvgl/lvgl.h"
#include "lvgl/examples/lv_examples.h" #include "lvgl/examples/lv_examples.h"
#include "lvgl/demos/lv_demos.h" #include "lvgl/demos/lv_demos.h"
@ -88,7 +95,11 @@ int main(int argc, char **argv)
/* Periodically call the lv_task handler. /* Periodically call the lv_task handler.
* It could be done in a timer interrupt or an OS task too.*/ * It could be done in a timer interrupt or an OS task too.*/
lv_timer_handler(); lv_timer_handler();
#ifdef _MSC_VER
Sleep(5);
#else
usleep(5 * 1000); usleep(5 * 1000);
#endif
} }
#elif LV_USE_OS == LV_OS_FREERTOS #elif LV_USE_OS == LV_OS_FREERTOS