Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Installation and Deployment
  4. [SOLVED]Cannot compile Qt 5.2 from Git for Android including mysql support
QtWS25 Last Chance

[SOLVED]Cannot compile Qt 5.2 from Git for Android including mysql support

Scheduled Pinned Locked Moved Installation and Deployment
13 Posts 4 Posters 9.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kshots
    wrote on last edited by
    #1

    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:

    bq. ./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:

    bq. /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.a@

    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)?

    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?

    It also bugs me that at the tail end of the compile command (where it fails for the first time), the compiler is being passed a "-L/usr/lib64/mysql", which is the host mysql library folder and not the target mysql library. Why is that being passed in at all?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      kshots
      wrote on last edited by
      #2

      Ok, I figured out a way to make this work. First off, the mariadb connector (version 1.0.0) is not compatible with mysql (specifically, it lacks the mysql_library_init function and one other I don't recall off the top of my head). However, the latest stable version in the bazaar sources do include the necessary functions to be compatible with mysql. These sources require openssl and iconv to be installed, so start with those installed in your API sysroot. Then:

      bq. mkdir /tmp/src
      cd /tmp/src
      bzr branch lp:mariadb-native-client
      cd maria-native-client

      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:

      @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
      #endif@

      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:

      @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.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kshots
        wrote on last edited by
        #3

        Ok, I figured I'd be nice and explain how to compile openssl. First, grab the sources from the openssl site. I used version 1.0.1e. Unpack, then execute the following:

        @RANLIB="$BR"ranlib CC="$BR"gcc ./Configure android-armv7 --prefix=$SR/usr
        ANDROID_DEV=$SR/usr make
        make install@

        ... and that's it, you now have openssl installed.

        1 Reply Last reply
        0
        • K Offline
          K Offline
          kshots
          wrote on last edited by
          #4

          ... and here's how you get iconv to compile: Grab the sources, and in the source dir, do the following:

          @STRIP="$BR"strip RANLIB="$BR"ranlib OBJDUMP="$BR"objdump AR="$BR"ar CC="$BR"gcc CFLAGS=--sysroot=$SR CPP="$BR"cpp CPPFLAGS=$CFLAGS ./configure --build=x86_64 --host=arm --prefix=$SR/usr --with-sysroot=$SR && make install@

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            Hi and welcome to devnet,

            Thanks for sharing your solution. You could create a wiki page with the complete solution. It might be easier for other forum users to find it.

            In between, please update the thread title to solved, so other forum user may know a solution has been found :)

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • K Offline
              K Offline
              kshots
              wrote on last edited by
              #6

              You're probably right. I wrote up a wiki "here":http://qt-project.org/wiki/Build_Qt5_mysql_plugin_for_Android

              1 Reply Last reply
              0
              • P Offline
                P Offline
                projetoslinux
                wrote on last edited by
                #7

                Hi for all

                this wiki is great

                I have sucess but only in 2 last commands , i have error
                its possible help-me

                my ubuntu is 12.04
                my dir is /home/fuinha/Qt5.2.0/5.2.0/

                my error in

                "$BR"objdump -p libqsqlmysql.so | grep NEEDED

                -->> 'libqsqlmysql.so': No such file

                why NEEDED

                im my /Qt5.2.0/5.2.0/Src/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

                -->>bash: ../../../../bin/qmake: No such file or directory

                i work in
                /home/fuinha/Qt5.2.0/5.2.0/gcc_64/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

                -->> .../gcc_64/include/QtCore -I.moc main.cpp -o .moc/main.moc
                moc: Cannot create .moc/main.moc
                make: *** [.moc/main.moc] Error 1

                and
                /home/fuinha/Qt5.2.0/5.2.0/android_armv7/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

                ---->>>
                Project ERROR: You need to set the ANDROID_NDK_ROOT environment variable to point to your Android NDK.
                Could not read qmake configuration file /home/fuinha/Qt5.2.0/5.2.0/Src/qtbase/mkspecs/android-g++/qmake.conf.
                Error processing project file: mysql.pro

                Sorry for my newbie questions and thanks for help-me

                1 Reply Last reply
                0
                • K Offline
                  K Offline
                  kshots
                  wrote on last edited by
                  #8

                  The first error you posted:

                  ../../../../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

                  —>>bash: ../../../../bin/qmake: No such file or directory

                  Implies that you did not build qt before executing those commands. You must first build qt 5.2.0 (as you have selected) with whatever options you want, minus the mysql database options. This will in turn produce the "qmake" executable that the error shows was never generated. This specific executable has all the correct parameters configured for android, which is why you need to use it rather than whatever version of Qt may be installed with your system.

                  1 Reply Last reply
                  0
                  • K Offline
                    K Offline
                    kshots
                    wrote on last edited by
                    #9

                    I also just noticed this section of your post:

                    “$BR“objdump -p libqsqlmysql.so | grep NEEDED

                    —>> ‘libqsqlmysql.so’: No such file

                    why NEEDED

                    Checking the wiki, it appears someone added a bit after my initial posting (one of the nice things about wikis :)). Whoever added that, what they're saying is that you need to add a list of dependencies to the APK image, and grepping for "NEEDED" will tell you what the dependencies for the plugin are (which should be the dependencies I listed at the top, but this is a good thing to check). You also need to do this after successfully building the plugin (which is why it couldn't find it), so given your problem with building the plugin, you shouldn't be running this yet.

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      projetoslinux
                      wrote on last edited by
                      #10

                      thanks i testing

                      1 Reply Last reply
                      0
                      • P Offline
                        P Offline
                        projetoslinux
                        wrote on last edited by
                        #11

                        tHANK YOU SOLVED FOR ME !!!!

                        1 Reply Last reply
                        0
                        • C Offline
                          C Offline
                          chjichin
                          wrote on last edited by
                          #12

                          Hi all,
                          I follow above steps to compiler, at the final step, i got the error message, pls help me, tks!
                          pos@pos-MS-7817:~/adt/qt5/qtbase/src/plugins/sqldrivers/mysql$ SR=~/adt/android-ndk-r10d/platforms/android-9/arch-arm
                          pos@pos-MS-7817:~/adt/qt5/qtbase/src/plugins/sqldrivers/mysql$ BR=~/adt/android-ndk-r10d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm-linux-androideabi-
                          pos@pos-MS-7817:~/adt/qt5/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
                          rm -f libqsqlmysql.so
                          g++ -Wl,--no-undefined -Wl,-O1 -fuse-ld=gold -Wl,-rpath,/usr/local/Qt-5.4.0/lib -shared -o libqsqlmysql.so .obj/main.o .obj/qsql_mysql.o .obj/moc_qsql_mysql_p.o -L/home/pos/adt/android-ndk-r10d/platforms/android-9/arch-arm/usr/lib/mariadb /home/pos/adt/android-ndk-r10d/platforms/android-9/arch-arm/usr/lib/mariadb/libmariadbclient.a /home/pos/adt/android-ndk-r10d/platforms/android-9/arch-arm/usr/lib/libssl.a /home/pos/adt/android-ndk-r10d/platforms/android-9/arch-arm/usr/lib/libcrypto.a /home/pos/adt/android-ndk-r10d/platforms/android-9/arch-arm/usr/lib/libiconv.a -lmysqlclient -L/home/pos/adt/qt5/qtbase/lib -lQt5Sql -lQt5Core -lpthread
                          /usr/bin/ld.gold: fatal error: /home/pos/adt/android-ndk-r10d/platforms/android-9/arch-arm/usr/lib/mariadb/libmariadbclient.a(libmariadb.c.o): unsupported ELF machine number 40
                          collect2: error: ld returned 1 exit status
                          make: *** [../../../../plugins/sqldrivers/libqsqlmysql.so] Error 1
                          pos@pos-MS-7817:~/adt/qt5/qtbase/src/plugins/sqldrivers/mysql$

                          1 Reply Last reply
                          0
                          • C Offline
                            C Offline
                            chjichin
                            wrote on last edited by
                            #13

                            Hi all,
                            I follow above steps to compiler, at the final step, i got the error message, pls help me, tks!
                            pos@pos-MS-7817:~/adt/qt5/qtbase/src/plugins/sqldrivers/mysql$ SR=~/adt/android-ndk-r10d/platforms/android-9/arch-arm
                            pos@pos-MS-7817:~/adt/qt5/qtbase/src/plugins/sqldrivers/mysql$ BR=~/adt/android-ndk-r10d/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86/bin/arm-linux-androideabi-
                            pos@pos-MS-7817:~/adt/qt5/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
                            rm -f libqsqlmysql.so
                            g++ -Wl,--no-undefined -Wl,-O1 -fuse-ld=gold -Wl,-rpath,/usr/local/Qt-5.4.0/lib -shared -o libqsqlmysql.so .obj/main.o .obj/qsql_mysql.o .obj/moc_qsql_mysql_p.o -L/home/pos/adt/android-ndk-r10d/platforms/android-9/arch-arm/usr/lib/mariadb /home/pos/adt/android-ndk-r10d/platforms/android-9/arch-arm/usr/lib/mariadb/libmariadbclient.a /home/pos/adt/android-ndk-r10d/platforms/android-9/arch-arm/usr/lib/libssl.a /home/pos/adt/android-ndk-r10d/platforms/android-9/arch-arm/usr/lib/libcrypto.a /home/pos/adt/android-ndk-r10d/platforms/android-9/arch-arm/usr/lib/libiconv.a -lmysqlclient -L/home/pos/adt/qt5/qtbase/lib -lQt5Sql -lQt5Core -lpthread
                            /usr/bin/ld.gold: fatal error: /home/pos/adt/android-ndk-r10d/platforms/android-9/arch-arm/usr/lib/mariadb/libmariadbclient.a(libmariadb.c.o): unsupported ELF machine number 40
                            collect2: error: ld returned 1 exit status
                            make: *** [../../../../plugins/sqldrivers/libqsqlmysql.so] Error 1
                            pos@pos-MS-7817:~/adt/qt5/qtbase/src/plugins/sqldrivers/mysql$

                            1 Reply Last reply
                            0

                            • Login

                            • Login or register to search.
                            • First post
                              Last post
                            0
                            • Categories
                            • Recent
                            • Tags
                            • Popular
                            • Users
                            • Groups
                            • Search
                            • Get Qt Extensions
                            • Unsolved