From 578d6a25cdb9ec038b18b2bcc05fde586da244d0 Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 15 Jul 2023 21:20:39 +0800 Subject: [PATCH] ... --- CMakeLists.txt | 2 +- include/pocketpy/export.h | 7 ++++--- src/pocketpy.cpp | 12 +++++++++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d22442fb..4e9c2b91 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,6 @@ else() target_link_libraries(${PROJECT_EXE_NAME} ${CMAKE_DL_LIBS}) endif() -if (CMAKE_SYSTEM_NAME STREQUAL "Windows" OR CMAKE_SYSTEM_NAME STREQUAL "Linux" OR CMAKE_SYSTEM_NAME STREQUAL "Darwin") +if(NOT ${CMAKE_SYSTEM_NAME} STREQUAL "Emscripten") target_link_libraries(${PROJECT_NAME} ${CMAKE_DL_LIBS}) endif() diff --git a/include/pocketpy/export.h b/include/pocketpy/export.h index 6bc5dced..2d5e39b0 100644 --- a/include/pocketpy/export.h +++ b/include/pocketpy/export.h @@ -25,11 +25,11 @@ #if TARGET_IPHONE_SIMULATOR // iOS, tvOS, or watchOS Simulator #define PK_SYS_PLATFORM "ios" - #define PK_SUPPORT_DYLIB 0 + #define PK_SUPPORT_DYLIB 4 #elif TARGET_OS_IPHONE // iOS, tvOS, or watchOS device #define PK_SYS_PLATFORM "ios" - #define PK_SUPPORT_DYLIB 0 + #define PK_SUPPORT_DYLIB 4 #elif TARGET_OS_MAC #define PK_SYS_PLATFORM "darwin" #include @@ -39,7 +39,8 @@ #endif #define PK_EXPORT __attribute__((visibility("default"))) #elif __ANDROID__ - #define PK_SUPPORT_DYLIB 0 + #include + #define PK_SUPPORT_DYLIB 3 #define PK_EXPORT __attribute__((visibility("default"))) #define PK_SYS_PLATFORM "android" #elif __linux__ diff --git a/src/pocketpy.cpp b/src/pocketpy.cpp index 2a9e41fd..0d38bf14 100644 --- a/src/pocketpy.cpp +++ b/src/pocketpy.cpp @@ -7,6 +7,7 @@ using dylib_entry_t = const char* (*)(void*, const char*); #if PK_ENABLE_OS #if PK_SUPPORT_DYLIB == 1 +// win32 static dylib_entry_t load_dylib(const char* path){ std::error_code ec; auto p = std::filesystem::absolute(path, ec); @@ -32,7 +33,7 @@ static dylib_entry_t load_dylib(const char* path){ return (dylib_entry_t)GetProcAddress(handle, "platform_module__init__"); } #elif PK_SUPPORT_DYLIB == 2 - +// linux/darwin static dylib_entry_t load_dylib(const char* path){ std::error_code ec; auto p = std::filesystem::absolute(path, ec); @@ -41,6 +42,15 @@ static dylib_entry_t load_dylib(const char* path){ if(!handle) return nullptr; return (dylib_entry_t)dlsym(handle, "platform_module__init__"); } + +#elif PK_SUPPORT_DYLIB == 3 +// android +static dylib_entry_t load_dylib(const char* path){ + void* handle = dlopen(path, RTLD_LAZY); + if(!handle) return nullptr; + return (dylib_entry_t)dlsym(handle, "platform_module__init__"); +} + #else static dylib_entry_t load_dylib(const char* path){ return nullptr;