PDA

View Full Version : Configuring Qt5 to compile mysql for android



KShots
18th November 2013, 18:09
Hey all,

I'm having a difficult time compiling qt5 for android with mysql support. I've downloaded the mariadb connector sources, and configured CMake for mariadb to utilize the android toolchain (compiled and installed into API-9 for ARM in this case). However, when I run configure with the following switches:
./configure -prefix /home/rich/local/qt5android -xplatform android-g++ -nomake tests -nomake examples -android-ndk /opt/android-ndk -android-sdk /opt/android-sdk-update-manager -android-ndk-host linux-x86_64 -android-toolchain-version 4.8 -skip qttranslations -skip qtwebkit -skip qtserialport -skip qtwebkit-examples -no-warnings-are-errors -system-proxies -no-cups -plugin-sql-mysql -opensource -confirm-license -developer-build -debug -vI get errors about missing pthread, rt, and mysqlclient_r libraries:
/opt/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ --sysroot=/opt/android-ndk/platforms/android-9/arch-arm/ -Wl,--no-undefined -Wl,-z,noexecstack -shared -o mysql_r mysql.o -L/opt/android-ndk/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a -L/opt/android-ndk/platforms/android-9/arch-arm//usr/lib -L/usr/lib64/mysql -lpthread -lz -lm -lrt -lssl -lcrypto -ldl -lmysqlclient_r -lgnustl_shared -llog -lz -lm -ldl -lc -lgcc
/opt/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lpthread
/opt/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lrt
/opt/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: warning: skipping incompatible /usr/lib64/mysql/libmysqlclient_r.so while searching for mysqlclient_r
/opt/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lmysqlclient_r
collect2: error: ld returned 1 exit status
gmake: *** [mysql_r] Error 1
MySQL (thread-safe) disabled.
MySQL (thread-unsafe) auto-detection... ()
/opt/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ -c -Wno-psabi -march=armv7-a -mfloat-abi=softfp -mfpu=vfp -ffunction-sections -funwind-tables -fstack-protector -fno-short-enums -DANDROID -Wa,--noexecstack -std=gnu++0x -O2 -mthumb -Os -fomit-frame-pointer -fno-strict-aliasing -finline-limit=64 -Wall -Wno-psabi -W -fPIE -DQT_NO_PRINTER -DQT_NO_PRINTDIALOG -I../../../mkspecs/android-g++ -I. -I/usr/include/mysql -I/opt/android-ndk/sources/cxx-stl/gnu-libstdc++/4.8/include -I/opt/android-ndk/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a/include -I/opt/android-ndk/platforms/android-9/arch-arm/usr/include -o mysql.o mysql.cpp
/opt/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-g++ --sysroot=/opt/android-ndk/platforms/android-9/arch-arm/ -Wl,--no-undefined -Wl,-z,noexecstack -shared -o mysql mysql.o -L/opt/android-ndk/sources/cxx-stl/gnu-libstdc++/4.8/libs/armeabi-v7a -L/opt/android-ndk/platforms/android-9/arch-arm//usr/lib -L/usr/lib64/mysql -lpthread -lz -lm -lrt -lssl -lcrypto -ldl -lmysqlclient -lgnustl_shared -llog -lz -lm -ldl -lc -lgcc
/opt/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lpthread
/opt/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.8/../../../../arm-linux-androideabi/bin/ld: error: cannot find -lrt
collect2: error: ld returned 1 exit status
gmake: *** [mysql] Error 1
MySQL (thread-unsafe) disabled.
MySQL support cannot be enabled due to functionality tests!Here's the contents of my lib dir under my API 9 sysroot:
ls /opt/android-ndk/platforms/android-9/arch-arm/usr/lib
crtbegin_dynamic.o libcrypto.a libGLESv2.so libmariadb.so.1 libncurses++.a libreadline.so.6 libtinfo.a
crtbegin_so.o libc.so libhistory.a libmenu.a libncurses_g.a libssl.a libtinfo_g.a
crtbegin_static.o libdl.so libhistory.so.6 libmenu_g.a libncurses_p.a libstdc++.a libtinfo_p.a
crtend_android.o libEGL.so libjnigraphics.so libmenu_p.a libOpenSLES.so libstdc++.so libz.so
crtend_so.o libform.a liblog.so libm_hard.a libpanel.a libthread_db.so pkgconfig
engines libform_g.a libm.a libm.so libpanel_g.a libtic.a terminfo
libandroid.so libform_p.a libmariadbclient.a libmysqlclient.a libpanel_p.a libtic_g.a
libc.a libGLESv1_CM.so libmariadb.so libncurses.a libreadline.a libtic_p.aNote that the 'libmysqlclient.a' file is actually a symlink to libmariadbclient.a (IIRC, the API is the exact same, and so all symbols should line up. This does not happen out of the box, I made the symlink manually). Why is the qt5 configure script complaining about these missing libs (especially pthread and rt)?

KShots
19th November 2013, 14:57
Also, I was unable to figure out how to generate any "lib*client_r.{a,so}" libraries for mariadb. What can I do to manually tweak what Qt is looking for in its configure script (pthread and rt are built-in and should not be attempting to link), as it's clearly broken?

KShots
19th November 2013, 17:39
Ok, I finally got it working. Yes, it turns out that the mysql capability for building from the configure script for android is completely broken, you have to do this manually.

First, grab the mariadb connector from bazaar (the 1.0.0 release is not compatible with mysql, despite what they claim - it's missing mysql_libary_init, for one). The bazaar sources _are_ compatible, however, and they work for the purposes of compiling qt mysql support for android. For the solution below, I will (for now) assume that you have successfully installed openssl and iconv into your android-9 API sysroot. At this point, you can make and install mariadb. So... open up a shell session. We will put our sources into /tmp/src:
mkdir /tmp/src
cd /tmp/src
bzr branch lp:mariadb-native-client
cd maria-native-clientThe unit tests for mariadb fail with some missing pthread capabilities, so once you checkout the sources as shown above, and _before_ executing cmake as shown below, open up unittest/libmariadb/CMakeLists.txt and comment _everything_ out. Then do the following:
mkdir build && cd build
export BR=/opt/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
export SR=/opt/android-ndk/platforms/android-9/arch-arm
PKG_CONFIG_PATH=$SR/usr/lib/pkgconfig cmake -DCMAKE_AR="$BR"ar -DCMAKE_BUILD_TYPE=Release -DCMAKE_C_COMPILER="$BR"gcc -DCMAKE_C_FLAGS=--sysroot=$SR -DCMAKE_INSTALL_PREFIX=$SR/usr -DCMAKE_LINKER="$BR"ld -DCMAKE_NM="$BR"nm -DCMAKE_OBJCOPY="$BR"objcopy -DCMAKE_OBJDUMP="$BR"objdump -DCMAKE_RANLIB="$BR"ranlib -DCMAKE_STRIP="$BR"strip -DWITH_EXTERNAL_ZLIB=ON -DICONV_INCLUDE_DIR=$SR/usr/include -DICONV_LIBRARIES=$SR/usr/lib/libiconv.a -DZLIB_INCLUDE_DIR=$SR/usr/include -DZLIB_LIBRARY=$SR/usr/lib/libz.so ../This should configure the project successfully. However, the android build tools don't have a clue what 'ushort' is, and it is used throughout the project. So... open up ../include/my_global.h and insert the following inside the #define _global_h block:
#ifndef ushort
#define ushort uint16
#endifThis should replace every instance of 'ushort' with 'uint16' if (and only if) the compiler doesn't know what ushort is.

Now, to compile mysql support in Qt, you need to configure Qt for android as usual, but make _sure_ you don't enable the qt-sql-mysql or plugin-sql-mysql flags for configure (these will fail no matter what you do). Now, export qt=PATH_TO_QT_SOURCE_TREE and do the following:
cd $qt/qtbase/src/plugins/sqldrivers/mysql
../../../../bin/qmake "INCLUDEPATH+=$SR/usr/include/mariadb" "LIBS+=$SR/usr/lib/mariadb/libmariadbclient.a $SR/usr/lib/libssl.a $SR/usr/lib/libcrypto.a $SR/usr/lib/libiconv.a" "LIBPATH+=$SR/usr/lib/mariadb" -o Makefile mysql.pro
make install... and that's it. Now you have a qmysql plugin utilizing the mariadb C connector for android.