native icon indicating copy to clipboard operation
native copied to clipboard

[ffi] pthread_mutex_t variable defined in main causing dlopen failed: cannot locate symbol error

Open pangz-lab opened this issue 1 year ago • 2 comments

I loaded the pre-compiled libmylib.so including the libc++_shared.so in flutter android. Inside the main.cpp I have a variable defined like the following.

pthread_mutex_t stratum_work_lock;

I created the ffi for main only. int main(int argc, char *argv[]) When running the .so file, I got this error dlopen failed: cannot locate symbol "stratum_sock_lock"

I wonder what's causing the error or if I'm missing something.

I only need to exposed the main method as it's all I need to call. Any pointers would be appreciated.

pangz-lab avatar Apr 04 '24 08:04 pangz-lab

It sounds like the dynamic linker tries to find the required symbol during dlopen and can't find the one.

Did you declare but not define the variable? https://stackoverflow.com/questions/1410563/what-is-the-difference-between-a-definition-and-a-declaration

dcharkes avatar Apr 04 '24 12:04 dcharkes

Thank you for the response. The variable is declared and defined.

The binary was working as expected using the Process library but the equivalent .so file is not. At first the DynamicLibrary complained that the libc++_shared.so cannot be found. Then I added the one from Android NDK, after running again, this is the error I got.

pangz-lab avatar Apr 06 '24 02:04 pangz-lab