Search code examples
androidqtgdal

libgdal.so android error: could not load library "libgdal.so.1"


My problem is the following: I have succesfully built GDAL 1.10.1 using an Android toolchain (CC=i686-linux-android-gcc, CXX=i686-linux-android-c++) that produces the following output libraries libgdal.a, libgdal.la, libgdal.lai, libgdal.so, libgdal.so.1, libgdal.so.1.17.1 in the output folder .libs (in the following I'll call this folder $GDAL_LIB_PATH).

I am trying to build a simple Android app (a simple widget application with a QPushButton named TestAndroid) using Qt 5.4 on Windows. If I don't use GDAL everything works fine and I am able to run my app on an Android emulator for all available platforms: x86, armeabi and armeabi-v7.

Nonetheless, if I try to use GDAL (ex. by simply calling GDALAllRegister() in the initialization of the app) and then linking to libgdal.so the application crashes with the following error:

E/art ( 1614): dlopen("/data/app/org.qtproject.example.TestAndroid-1/lib/x86/libTestAndroid.so", RTLD_LAZY) failed: dlopen failed: could not load library "libgdal.so.1" needed by "libTestAndroid.so"; caused by library "libgdal.so.1" not found

I have verified that the Android platform is the right one (x86), otherwise the linker would skip the wrong libgdal.so object.

I have included libgdal.so in the *.apk (generated by Qt) using ANDROID_EXTRA_LIBS *= $GDAL_LIB_PATH/libgdal.so. The other files libgdal.so.x.x cannot be included in the same way since Qt prevents it.

In order to avoid dynamic linking I have also tried to link my app with libgdal.a but many link-time errors appears (ex. undefined reference to 'atof')

I have searched on the web but I have not found a solution to my problem.

I am not constrained to use dynamic linking so, a solution to any of the following problems is good for me:

  1. Is there a way to avoid the creation of libgdal.so.x.x files when building GDAL ?

  2. Is there a way to include libgdal.so.x.x files in the *.apk file generated by Qt ?

  3. How can I avoid link-time errors when linking the static library libgdal.a ?

Thanks in advance for any reply!


Solution

  • After several days of trials and errors (mainly errors) I have found a solution to my problem.

    I'm writing it as an answer to my question so that it may be helpful to others.

    The problem was during the link-time of GDAL. Briefly: the linker created the "real name" shared library libgdal.so.1.17.1 together with the links to it libgdal.so.1 and libgdal.so.

    For some reasons (which I ignore) forcing the link to libgdal.so, the linker searches for libgdal.so.1 (which, in turn, would have searched for libgdal.so.1.17.1).

    The workaround that solved my problem can be summarized in the following steps:

    1. In the GDAL root, run the ./configure according to the desired configuration (see http://trac.osgeo.org/gdal/wiki/BuildingForAndroid) checking that libtool is ENABLED

    2. Edit the created libtool file (e. g. with gedit) as follows:

      • replace the value of library_names_spec with library_names_spec="\$libname\${shared_ext}"
      • replace the value of soname_spec with soname_spec=""
    3. Type make

    In the output folder .libs/ the only libgdal.so will be created and now the link to libgdal.so seems to work fine.