Open liquanqing opened 4 months ago
Last time we saw a dll import issue @kdschlosser investigated it. Kevin, do you know what can be the problem with ThorVG?
Can you paste the compiler output into a post for me so I can see what is happening?
all api in thorvg are show error as follow : lvgl-9.1.0\src\libs\thorvg\tvgCapi.cpp:63:20: error: function 'Tvg_Result tvg_canvas_destroy(Tvg_Canvas)' definition is marked dllimport [build] TVG_API Tvg_Result tvg_canvas_destroy(Tvg_Canvas canvas)
lvgl-9.1.0\src\libs\thorvg\tvgCapi.cpp:498:20: error: function 'Tvg_Result tvg_shape_get_gradient(const Tvg_Paint*, Tvg_Gradient*)' definition is marked dllimport [build] TVG_API Tvg_Result tvg_shape_get_gradient(const Tvg_Paint paint, Tvg_Gradient** gradient)
and this is my cmake file written : set(SDL2_RELEASE_DIR source/thirdparty/SDL2-devel-2.30.4-mingw)
find_package(SDL2 2.30.4 PATHS ${SDL2_RELEASE_DIR})
message(STATUS "SDL2_DIR = ${SDL2_DIR}") message(STATUS "SDL2_INCLUDE_DIRS = ${SDL2_INCLUDE_DIRS}") message(STATUS "SDL2_LIBDIR = ${SDL2_LIBDIR}") message(STATUS "SDL2_BINDIR = ${SDL2_BINDIR}") message(STATUS "SDL2_LIBRARIES = ${SDL2_LIBRARIES}") message(STATUS "SDL2_FOUND = ${SDL2_FOUND}")
MESSAGE(STATUS "project_source" "${PROJECT_SOURCE_DIR}")
set(LVGL_SRC_DIR ${ROOT_PATH}/source/thirdparty/lvgl) set(LVGL_VERSION 9.1.0) set(LVGL_SIM_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}) message(STATUS "LVGL path " ${LVGL_SRC_DIR}-${LVGL_VERSION})
option(LV_USE_DRAW_SDL "Use SDL draw unit" OFF) option(LV_USE_LIBPNG "Use libpng to decode PNG" OFF) option(LV_USE_LIBJPEG_TURBO "Use libjpeg turbo to decode JPEG" OFF) option(LV_USE_FFMPEG "Use libffmpeg to display video using lv_ffmpeg" OFF) option(LV_USE_FREETYPE "Use freetype lib" OFF) option(LV_CONF_BUILD_DISABLE_THORVG_INTERNAL "Disable building thorvg library" OFF)
MESSAGE(STATUS "lvgl source dir: ${LVGL_SRC_DIR}-${LVGL_VERSION}") add_subdirectory(${LVGL_SRC_DIR}-${LVGL_VERSION})
add_subdirectory(lvgl_sim_src)
in lvgl_sim_src directory 's CMakeLists.txt is : message(STATUS "get ROOT_PATH" ${ROOT_PATH}) message(STATUS "cur path " ${CMAKE_CURRENT_SOURCE_DIR})
target_include_directories(lvgl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${LVGL_SRC_DIR}-${LVGL_VERSION} ${SDL2_INCLUDE_DIRS}) target_compile_options(lvgl PRIVATE -DLV_CONF_PATH=lv_conf.h)
add_executable(lvgl_main main.c mouse_cursor_icon.c) target_link_directories(lvgl_main PRIVATE ${SDL2_LIBDIR}) target_include_directories(lvgl_main PUBLIC ${LVGL_SRC_DIR}-${LVGL_VERSION} ${SDL2_INCLUDE_DIRS}) target_link_libraries(lvgl_main lvgl lvgl::examples lvgl::demos lvgl::thorvg -lmingw32 ${SDL2_LIBRARIES} m pthread)
add_custom_command(TARGET lvgl_main POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${SDL2_BINDIR}/SDL2.dll $
@kisvegabor
It's easy to locate the issue...
This is the compiler output
all api in thorvg are show error as follow :
lvgl-9.1.0\src\libs\thorvg\tvgCapi.cpp:63:20: error: function 'Tvg_Result tvg_canvas_destroy(Tvg_Canvas*)' definition is marked dllimport << ------ RIGHT HERE
[build] TVG_API Tvg_Result tvg_canvas_destroy(Tvg_Canvas* canvas)
lvgl-9.1.0\src\libs\thorvg\tvgCapi.cpp:498:20: error: function 'Tvg_Result tvg_shape_get_gradient(const Tvg_Paint*, Tvg_Gradient**)' definition is marked dllimport << ------ RIGHT HERE
[build] TVG_API Tvg_Result tvg_shape_get_gradient(const Tvg_Paint* paint, Tvg_Gradient** gradient)
searching for the function tvg_canvas_destroy
we find the following..
thorvg_capi.h
TVG_API Tvg_Result tvg_canvas_destroy(Tvg_Canvas* canvas);
tvgCapi.cpp
TVG_API Tvg_Result tvg_canvas_destroy(Tvg_Canvas* canvas)
{
if (!canvas) return TVG_RESULT_INVALID_ARGUMENT;
delete(reinterpret_cast<Canvas*>(canvas));
return TVG_RESULT_SUCCESS;
}
and when we look up what TVG_API is this is what is found in thorvg_capi.h
#ifndef TVG_STATIC
#ifdef _WIN32
#if TVG_BUILD
#define TVG_API __declspec(dllexport)
#else
#define TVG_API __declspec(dllimport)
#endif
#elif (defined(__SUNPRO_C) || defined(__SUNPRO_CC))
#define TVG_API __global
#else
#if (defined(__GNUC__) && __GNUC__ >= 4) || defined(__INTEL_COMPILER)
#define TVG_API __attribute__ ((visibility("default")))
#else
#define TVG_API
#endif
#endif
#else
#define TVG_API
#endif
and there you have it. an undocumented macro.. TVG_BUILD
needs to be set so that it will mark the functions as exports.
@liquanqing
add -DTVG_BUILD=1
to your C and CPP compiler flags and that should do the trick.
i had add -DTVG_BUILD=1 and the error still happened, here is my modified :
message(STATUS "get ROOT_PATH" ${ROOT_PATH})
message(STATUS "cur path " ${CMAKE_CURRENT_SOURCE_DIR})
set(CMAKE_C_FLAGS "-DTVG_BUILD=1 ${CMAKE_C_FLAGS}")
set(CMAKE_CXX_FLAGS "-DTVG_BUILD=1 ${CMAKE_CXX_FLAGS}")
target_include_directories(lvgl PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${LVGL_SRC_DIR}-${LVGL_VERSION} ${SDL2_INCLUDE_DIRS})
target_compile_options(lvgl PRIVATE -DLV_CONF_PATH=lv_conf.h -DTVG_BUILD=1)
add_executable(lvgl_main main.c mouse_cursor_icon.c)
target_link_directories(lvgl_main PRIVATE
${SDL2_LIBDIR})
target_include_directories(lvgl_main PUBLIC ${LVGL_SRC_DIR}-${LVGL_VERSION} ${SDL2_INCLUDE_DIRS})
target_link_libraries(lvgl_main lvgl lvgl::examples lvgl::demos lvgl::thorvg -lmingw32 ${SDL2_LIBRARIES} m pthread)
add_custom_command(TARGET lvgl_main POST_BUILD
COMMAND ${CMAKE_COMMAND} -E copy_if_different
${SDL2_BINDIR}/SDL2.dll $<TARGET_FILE_DIR:lvgl_main>)
@kdschlosser
i do a little change, and it worked.
target_compile_options(lvgl PUBLIC -DLV_CONF_PATH=lv_conf.h -DTVG_BUILD=1)
Thanks.
compiler is successful. and i run lvgl_main.exe vector_graphic
and it maybe call some wrong.
That is going to be in @kisvegabor 's court to help you. I know the build systems and documentation. LVGL's inner workings are not my strong area especially the vector graphics stuff.
Awesome! Please try modifying this part to
target_compile_definitions(lvgl
INTERFACE LV_ATTRIBUTE_EXTERN_DATA=__declspec\(dllimport\)
PRIVATE LV_ATTRIBUTE_EXTERN_DATA=__declspec\(dllexport\)
PRIVATE TVG_BUILD=1
)
Hi, in windows, i use cmake with mingW compile successful except lvgl_thorvg; but using LV_CONF_BUILD_DISABLE_THORVG_INTERNAL = ON to enable lvgl_thorvg , it compile error with "definition is marked dllimport ". how can i fix it ?