Skip to content

Commit

Permalink
获取当前SO库的安装路径
Browse files Browse the repository at this point in the history
  • Loading branch information
HEYAHONG committed Jan 9, 2025
1 parent 6f24099 commit 70cbf6c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
3 changes: 2 additions & 1 deletion test/Android/HelloWorld/app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ hrc_enable(${PROJECT_NAME})
target_link_libraries(${CMAKE_PROJECT_NAME}
# List libraries link to the target library
android
log)
log
dl)
19 changes: 19 additions & 0 deletions test/Android/HelloWorld/app/src/main/cpp/native-lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,28 @@
#include "hbox.h"
#include "HCPPBox.h"
#include <android/log.h>
#include <dlfcn.h>

#define LOGI(...) \
((void)__android_log_print(ANDROID_LOG_INFO, "helloworld-libs::", __VA_ARGS__))


static std::string GetCurrentLibPATH()
{
std::string ret;
void * handle = dlopen(NULL,RTLD_LAZY);
if(handle!=NULL)
{
Dl_info info= {0};
if(dladdr((const void *)GetCurrentLibPATH,&info))
{
ret=info.dli_fname;
}
dlclose(handle);
}
return ret;
}

extern "C" JNIEXPORT jstring JNICALL
Java_cn_hyhsystem_hcppbox_helloworld_MainActivity_stringFromJNI(
JNIEnv* env,
Expand All @@ -34,6 +52,7 @@ extern "C"
JNIEXPORT void JNICALL
Java_cn_hyhsystem_hcppbox_helloworld_MainActivity_Init(JNIEnv *env, jobject thiz) {
LOGI("Init");
LOGI("Lib_PATH:%s",GetCurrentLibPATH().c_str());
}

/*
Expand Down

0 comments on commit 70cbf6c

Please sign in to comment.