Reputation: 7828
I have a native library ('processor') that I'm building with the Android NDK that depends on libjpeg. This issue might be unrelated to the Android aspect however. I've successfully built the library, but when I attempt to run the library fails to load properly with this error:
failed: dlopen failed: cannot locate symbol "jpeg_mem_src"
However if I nm -D processor.so
it does indeed contain the symbols:
...
U jpeg_CreateCompress
U jpeg_CreateDecompress
U jpeg_destroy_compress
U jpeg_destroy_decompress
U jpeg_finish_compress
U jpeg_finish_decompress
U jpeg_mem_dest
U jpeg_mem_src
U jpeg_read_header
U jpeg_read_scanlines
...
processor build.gradle:
sources {
main {
jni {
dependencies {
project ":jpeg"
}
}
}
}
ndk {
moduleName "processor"
cppFlags.add("-fexceptions")
ldLibs.add("log")
stl "gnustl_shared"
}
The java side loads it with:
static
{
try
{
Log.i("JNI", "Trying to load lib");
System.loadLibrary("gnustl_shared");
System.loadLibrary("processor");
}
catch (UnsatisfiedLinkError ule)
{
Log.e("JNI", ule.toString());
}
}
Any idea why the symbols exist, but can't be found? Thanks!
Upvotes: 2
Views: 1753
Reputation: 532
Depending on Android versions, you will have to load the jpeg library manually (and include it in your apk too !)
So just add a System.loadLibrary("jpeg");
to your static block, and it should do the trick.
Btw, the fact that you can see the symbols in your .so
file only means that your file is using them, not that your .so
provides an implementation. You can see it as nm
reports the symbols with the U
letter, for undefined
.
Upvotes: 2