How to resolve dependency between .so libraries, the cannot locate symbol "cblas_sdsdot" referenced by "libgsl.so" error.

1,205 views
Skip to first unread message

shekmun

unread,
Dec 29, 2015, 1:33:57 PM12/29/15
to android-ndk
I want to compile the gsl with ndk and use it on my android phone. And this is my steps:
1, Download the gsl-2.1.tar.gz and unzip it
2, ./configure -> make -> make install inside the gsl folder:
  a) ./configure --prefix=/path/to/install/directory --host="arm-linux-androideabi" --with-sysroot="/path/to/android-ndk-r10e/platforms/android-16/arch-arm" CC="/path/to/android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc" STRIP="/path/to/android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip" CFLAGS="--sysroot=/path/to/android-ndk-r10e/platforms/android-16/arch-arm -DANDROID -fPIC -ffunction-sections -funwind-tables -fstack-protector -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16 -fomit-frame-pointer -fstrict-aliasing -funswitch-loops -finline-limit=300" LDFLAGS="-nostdlib -Wl,--fix-cortex-a8" LIBS="-lgcc -ldl -lz -lm -lc"
  b) make -j4
  c) make install-strip
3, Now I get the libgsl.so and libgslcblas.so.
4, If I use the readelf to check the two librarys I get this:
  a) readelf -Ws libgsl.so | grep UND
     0: 00000000     0 NOTYPE  LOCAL  DEFAULT  UND 
     1: 00000000     0 FUNC    GLOBAL DEFAULT  UND __cxa_finalize
     2: 00000000     0 FUNC    GLOBAL DEFAULT  UND __cxa_atexit
     6: 00000000     0 FUNC    GLOBAL DEFAULT  UND malloc
     7: 00000000     0 FUNC    GLOBAL DEFAULT  UND free
    10: 00000000     0 FUNC    GLOBAL DEFAULT  UND memset
    52: 00000000     0 FUNC    GLOBAL DEFAULT  UND fread
    54: 00000000     0 FUNC    GLOBAL DEFAULT  UND fwrite
    62: 00000000     0 FUNC    GLOBAL DEFAULT  UND putc
    63: 00000000     0 FUNC    GLOBAL DEFAULT  UND fprintf
    65: 00000000     0 FUNC    GLOBAL DEFAULT  UND fscanf
   189: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND cblas_sdsdot ********pay attention this line******
   191: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND cblas_dsdot
   193: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND cblas_sdot
   195: 00000000     0 NOTYPE  GLOBAL DEFAULT  UND cblas_ddot
  b) readelf -Ws libgslcblas.so | grep cblas_sdsdot
    12: 0000298c   268 FUNC    GLOBAL DEFAULT    8 cblas_sdsdot
5, See, the libgsl.so has an undefined symbol link "cblas_sdsdot" and libgslcblas.so defines it.
6, Add the libgsl.so and libgslcblas.so to my android studio. And load the two libraries with java code:
System.loadLibrary("gslcblas");
System.loadLibrary("gsl");
And when it runs to loadLibrary("gsl") the app will crash.
This is the error message:
dlopen("/data/app/com.ict.hci.iwatcher-2/lib/arm/libgsl.so", RTLD_LAZY) failed: dlopen failed: cannot locate symbol "cblas_sdsdot" referenced by "libgsl.so"...
It tell me that cannot find "cblas_sdsdot" and it is not defined libgsl.so but in libgslcblas.so. So how to tell android to find the symbol in libgslcblas.so?
7, I'm working on ubuntu 15.10(x64), android studio 1.5, ndk-r10e. I get the error on android 4.2, 4.4 and 5.0.

Radovan Chytracek

unread,
Dec 29, 2015, 2:01:35 PM12/29/15
to andro...@googlegroups.com
Hi,

do you perform dlopen yourselves or you rely on the default systems setting for the shared object symbols resolution?

Radovan

--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at https://groups.google.com/group/android-ndk.
For more options, visit https://groups.google.com/d/optout.

J Decker

unread,
Dec 29, 2015, 4:21:14 PM12/29/15
to andro...@googlegroups.com
dlopen libglscblas.so first?

shekmun

unread,
Dec 30, 2015, 11:29:14 AM12/30/15
to android-ndk
I'm using the java code System.loadLibrary("gslcblas"); and then System.loadLibrary("gsl");
As you can see from the error message it's some c++ code like:
dlopen("/data/app/com.ict.hci.iwatcher-2/lib/arm/libgsl.so", RTLD_LAZY)

在 2015年12月30日星期三 UTC+8上午3:01:35,Radovan Chytracek写道:

shekmun

unread,
Dec 30, 2015, 11:29:14 AM12/30/15
to android-ndk
Yes, I'm loading the libgslcblas first.

在 2015年12月30日星期三 UTC+8上午5:21:14,J Decker写道:

shekmun

unread,
Dec 30, 2015, 11:29:22 AM12/30/15
to android-ndk
I've tried this native c++ code and the ret always be 10:
    int ret = 0;
    if (dlopen("/sdcard/Download/libgslcblas.so", RTLD_LAZY | RTLD_GLOBAL) == NULL) ret += 1;
    if (dlopen("/sdcard/Download/libgsl.so", RTLD_LAZY | RTLD_GLOBAL) == NULL) ret += 10;
    //ret always be 10


在 2015年12月30日星期三 UTC+8上午2:33:57,shekmun写道:

shekmun

unread,
Jan 19, 2016, 10:12:26 AM1/19/16
to android-ndk
Ok, it was solved. When compiling the gsl library, we need to set the dependency of gsl to the cblas library. See this: https://github.com/bytedeco/javacpp/issues/55
Just add " GSL_LDFLAGS="-Lcblas/.libs/ -lgslcblas" " to the ./configure command.


在 2015年12月30日星期三 UTC+8上午2:33:57,shekmun写道:
I want to compile the gsl with ndk and use it on my android phone. And this is my steps:
Reply all
Reply to author
Forward
0 new messages