Results 1 to 3 of 3

Thread: Configuring Qt5 to compile mysql for android

  1. #1
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Question Configuring Qt5 to compile mysql for android

    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 -v
    I 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:
    Qt Code:
    1. ls /opt/android-ndk/platforms/android-9/arch-arm/usr/lib
    2. crtbegin_dynamic.o libcrypto.a libGLESv2.so libmariadb.so.1 libncurses++.a libreadline.so.6 libtinfo.a
    3. crtbegin_so.o libc.so libhistory.a libmenu.a libncurses_g.a libssl.a libtinfo_g.a
    4. crtbegin_static.o libdl.so libhistory.so.6 libmenu_g.a libncurses_p.a libstdc++.a libtinfo_p.a
    5. crtend_android.o libEGL.so libjnigraphics.so libmenu_p.a libOpenSLES.so libstdc++.so libz.so
    6. crtend_so.o libform.a liblog.so libm_hard.a libpanel.a libthread_db.so pkgconfig
    7. engines libform_g.a libm.a libm.so libpanel_g.a libtic.a terminfo
    8. libandroid.so libform_p.a libmariadbclient.a libmysqlclient.a libpanel_p.a libtic_g.a
    9. libc.a libGLESv1_CM.so libmariadb.so libncurses.a libreadline.a libtic_p.a
    To copy to clipboard, switch view to plain text mode 
    Note 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)?
    Life without passion is death in disguise

  2. #2
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Configuring Qt5 to compile mysql for android

    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?
    Life without passion is death in disguise

  3. #3
    Join Date
    Feb 2006
    Location
    USA
    Posts
    142
    Thanks
    24
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Configuring Qt5 to compile mysql for android

    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:
    Qt Code:
    1. mkdir /tmp/src
    2. cd /tmp/src
    3. bzr branch lp:mariadb-native-client
    4. cd maria-native-client
    To copy to clipboard, switch view to plain text mode 
    The 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:
    Qt Code:
    1. mkdir build && cd build
    2. export BR=/opt/android-ndk/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-
    3. export SR=/opt/android-ndk/platforms/android-9/arch-arm
    4. 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 ../
    To copy to clipboard, switch view to plain text mode 
    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:
    Qt Code:
    1. #ifndef ushort
    2. #define ushort uint16
    3. #endif
    To copy to clipboard, switch view to plain text mode 
    This 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:
    Qt Code:
    1. cd $qt/qtbase/src/plugins/sqldrivers/mysql
    2. ../../../../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
    3. make install
    To copy to clipboard, switch view to plain text mode 
    ... and that's it. Now you have a qmysql plugin utilizing the mariadb C connector for android.
    Last edited by KShots; 19th November 2013 at 18:56.
    Life without passion is death in disguise

Similar Threads

  1. Replies: 4
    Last Post: 10th July 2014, 16:22
  2. How do you make android applications display correctly on android phone?
    By Cyrebo in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 17th August 2013, 08:31
  3. Replies: 1
    Last Post: 14th August 2013, 01:09
  4. Replies: 3
    Last Post: 12th December 2010, 12:46
  5. Compile QT4.2.2 with MySQL on Mac OS
    By asd in forum Installation and Deployment
    Replies: 7
    Last Post: 12th February 2007, 15:50

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.