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. Cross-compile MySQL driver for RPi3
Forum Updated to NodeBB v4.3 + New Features

Cross-compile MySQL driver for RPi3

Scheduled Pinned Locked Moved Unsolved Installation and Deployment
16 Posts 3 Posters 5.3k Views 1 Watching
  • 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.
  • E Offline
    E Offline
    endr
    wrote on last edited by
    #1

    Hi, I'm developing an application for Raspberrypi 3 that will interact with a mysql server. I'm using Yocto as operative system. I would like to cross-compile the driver for mysql. I'm developing on Ubuntu, I've installed libmysqlclient-dev and libmysqld-dev (via apt-get install). Following the tutorial I've added INCLUDEPATH and LIBS to my .pro file.

    
    QT       += core gui sql
    
    greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    
    TARGET = MySqlTest
    TEMPLATE = app
    target.path = /opt/$${TARGET}/bin
    INSTALLS += target
    
    SOURCES += main.cpp\
           widget.cpp
    INCLUDEPATH += /usr/include/mysql
    LIBS += -L/usr/lib/x86_64-linux-gnu -lmysqlclient_r
    
    HEADERS  += widget.h
    
    FORMS    += widget.ui
    
    

    When I try to build, deploy, then run it wont work, I get those errors:

    cannot find -lmysqlclient_r
    /usr/lib/x86_64-linux-gnu/libQt5Widgets.so:-1: error: file not recognized: File format not recognized

    What I'm doing wrong? Thanks for your help

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

      Hi and welcome to devnet,

      You are trying to link to your desktop version of the MySQL libraries. You need to use the the ARM version of them.

      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
      • E Offline
        E Offline
        endr
        wrote on last edited by endr
        #3

        How can I obtain the ARM version of the MySQL libraries in a folder on my local machine?
        I've tried downloading libmysqlclient-dev (via apt-get install) on Raspbian, then copied the /usr folder on my local machine. Then I've changed the path in INCLUDEPATH and LIBS as this:

        QT       += core gui sql
        
        greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
        
        TARGET = MySqlTest
        TEMPLATE = app
        target.path = /opt/$${TARGET}/bin
        INSTALLS += target
        
        SOURCES += main.cpp\
                widget.cpp
        INCLUDEPATH += /home/andrea/Scaricati/sysroot/usr/include/mysql
        LIBS += -L/home/andrea/Scaricati/sysroot/usr/lib/arm-linux-gnueabihf -lmysqlclient_r
        
        
        HEADERS  += widget.h
        
        FORMS    += widget.ui
        
        

        But it keeps giving me error such:
        cannot find libc.so.6
        cannot find libc_nonshared.a
        cannot find ld-linux-armhf.so.3

        Can you suggest the correct procedure (where to find the right libraries to download) and how to link them correctly in the .pro file?

        Thanks for your support

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

          You should use the sysroot of your device when cross-compiling so you ensure you have all the correct libraries available.

          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
          • E Offline
            E Offline
            endr
            wrote on last edited by
            #5

            I've copied the MySQL directory in the include folder of the poky's sysroot, and the shared mysqlclient libraries too in the /usr/lib directory like this:

            QT       += core gui sql
            
            greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
            
            TARGET = MySqlTest
            TEMPLATE = app
            target.path = /opt/$${TARGET}/bin
            INSTALLS += target
            
            SOURCES += main.cpp\
                    widget.cpp
            INCLUDEPATH += /opt/poky/2.3/sysroots/cortexa7hf-neon-vfpv4-poky-linux-gnueabi/usr/include/mysql
            LIBS += -L/opt/poky/2.3/sysroots/cortexa7hf-neon-vfpv4-poky-linux-gnueabi/usr/lib -lmysqlclient_r
            
            
            HEADERS  += widget.h
            
            FORMS    += widget.ui
            

            Now it gives me only one error:

            /opt/MySqlTest/bin/MySqlTest: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
            Application finished with exit code 127.
            

            What could it be?

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

              Are you running your application on your device when you get that error ?

              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
              • E Offline
                E Offline
                endr
                wrote on last edited by
                #7

                Yes, I run it from Qt to the remote RPi3. The application runs flawless if I use the Desktop kit. When I use the kit I've made for the Raspberry pi 3 (that has always worked fine) I get that error

                jsulmJ 1 Reply Last reply
                0
                • E endr

                  Yes, I run it from Qt to the remote RPi3. The application runs flawless if I use the Desktop kit. When I use the kit I've made for the Raspberry pi 3 (that has always worked fine) I get that error

                  jsulmJ Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @endr Does this file exist on your target device: libmysqlclient.so.18 ? If so where?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  1 Reply Last reply
                  0
                  • E Offline
                    E Offline
                    endr
                    wrote on last edited by
                    #9

                    If I copy :

                    libmysqlclient.a
                    libmysqlclient_r.a 
                    libmysqlclient_r.so 
                    libmysqlclient_r.so.18 
                    ibmysqlclient_r.so.18.0.0
                    libmysqlclient.so 
                    libmysqlclient.so.18 
                    libmysqlclient.so.18.0.0
                    

                    to /usr/lib on my target device I get:

                    QSqlDatabase: QMYSQL driver not loaded
                    QSqlDatabase: available drivers: 
                    

                    otherwise, without copying the shared libraries on the remote device (trying to crosscompile them from the local machine) I keep getting:

                    /opt/MySqlTest/bin/MySqlTest: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
                    Application finished with exit code 127.
                    

                    What can I do?

                    jsulmJ 1 Reply Last reply
                    0
                    • E endr

                      If I copy :

                      libmysqlclient.a
                      libmysqlclient_r.a 
                      libmysqlclient_r.so 
                      libmysqlclient_r.so.18 
                      ibmysqlclient_r.so.18.0.0
                      libmysqlclient.so 
                      libmysqlclient.so.18 
                      libmysqlclient.so.18.0.0
                      

                      to /usr/lib on my target device I get:

                      QSqlDatabase: QMYSQL driver not loaded
                      QSqlDatabase: available drivers: 
                      

                      otherwise, without copying the shared libraries on the remote device (trying to crosscompile them from the local machine) I keep getting:

                      /opt/MySqlTest/bin/MySqlTest: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
                      Application finished with exit code 127.
                      

                      What can I do?

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by jsulm
                      #10

                      @endr You can try to start your app like this:

                      QT_DEBUG_PLUGINS=1 && ./my_app
                      

                      You will get a lot of output, post it here.

                      The libraries you're copying: are those for your target (ARM)?

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0
                      • E Offline
                        E Offline
                        endr
                        wrote on last edited by
                        #11

                        @jsulm
                        I connect in ssh to the RPi3, start the application as you suggested:

                        root@rpi3:/opt/MySqlTest/bin# QT_DEBUG_PLUGINS=1 && ./MySqlTest 
                        ./MySqlTest: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
                        
                        

                        If I copy those shared libraries (from the libmysqlclient-dev package downloaded on a Raspbian OS) to /usr/lib I get this:

                        root@rpi3:/opt/MySqlTest/bin# QT_DEBUG_PLUGINS=1 && ./MySqlTest 
                        Unable to query physical screen size, defaulting to 100 dpi.
                        To override, set QT_QPA_EGLFS_PHYSICAL_WIDTH and QT_QPA_EGLFS_PHYSICAL_HEIGHT (in millimeters).
                        QSqlDatabase: QMYSQL driver not loaded
                        QSqlDatabase: available drivers: 
                        
                        jsulmJ 1 Reply Last reply
                        0
                        • E endr

                          @jsulm
                          I connect in ssh to the RPi3, start the application as you suggested:

                          root@rpi3:/opt/MySqlTest/bin# QT_DEBUG_PLUGINS=1 && ./MySqlTest 
                          ./MySqlTest: error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
                          
                          

                          If I copy those shared libraries (from the libmysqlclient-dev package downloaded on a Raspbian OS) to /usr/lib I get this:

                          root@rpi3:/opt/MySqlTest/bin# QT_DEBUG_PLUGINS=1 && ./MySqlTest 
                          Unable to query physical screen size, defaulting to 100 dpi.
                          To override, set QT_QPA_EGLFS_PHYSICAL_WIDTH and QT_QPA_EGLFS_PHYSICAL_HEIGHT (in millimeters).
                          QSqlDatabase: QMYSQL driver not loaded
                          QSqlDatabase: available drivers: 
                          
                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @endr What does

                          ldd PATH_TO_YOUR_QT/plugins/sqldrivers/libqsqlmysql.so
                          

                          on your RaspberryPi say?

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          1
                          • E Offline
                            E Offline
                            endr
                            wrote on last edited by
                            #13

                            There is no sqldrivers directory in qt5/plugins, just those:

                            root@rpi3:/usr/lib/qt5/plugins# ls -l 
                            total 68
                            drwxr-xr-x 2 root root 4096 Jun 14 10:51 bearer
                            drwxr-xr-x 2 root root 4096 Jun 14 11:44 canbus
                            drwxr-xr-x 2 root root 4096 Jun 14 10:51 egldeviceintegrations
                            drwxr-xr-x 2 root root 4096 Jun 14 10:51 generic
                            drwxr-xr-x 2 root root 4096 Jun 14 12:23 geoservices
                            drwxr-xr-x 2 root root 4096 Jun 14 11:43 iconengines
                            drwxr-xr-x 2 root root 4096 Jun 14 12:33 imageformats
                            drwxr-xr-x 2 root root 4096 Jun 14 12:24 lipi_toolkit
                            drwxr-xr-x 2 root root 4096 Jun 14 12:08 mediaservice
                            

                            What do I need to download?

                            jsulmJ 1 Reply Last reply
                            0
                            • E endr

                              There is no sqldrivers directory in qt5/plugins, just those:

                              root@rpi3:/usr/lib/qt5/plugins# ls -l 
                              total 68
                              drwxr-xr-x 2 root root 4096 Jun 14 10:51 bearer
                              drwxr-xr-x 2 root root 4096 Jun 14 11:44 canbus
                              drwxr-xr-x 2 root root 4096 Jun 14 10:51 egldeviceintegrations
                              drwxr-xr-x 2 root root 4096 Jun 14 10:51 generic
                              drwxr-xr-x 2 root root 4096 Jun 14 12:23 geoservices
                              drwxr-xr-x 2 root root 4096 Jun 14 11:43 iconengines
                              drwxr-xr-x 2 root root 4096 Jun 14 12:33 imageformats
                              drwxr-xr-x 2 root root 4096 Jun 14 12:24 lipi_toolkit
                              drwxr-xr-x 2 root root 4096 Jun 14 12:08 mediaservice
                              

                              What do I need to download?

                              jsulmJ Offline
                              jsulmJ Offline
                              jsulm
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              @endr How did you install Qt on RaspberryPi?

                              https://forum.qt.io/topic/113070/qt-code-of-conduct

                              1 Reply Last reply
                              0
                              • E Offline
                                E Offline
                                endr
                                wrote on last edited by
                                #15

                                I'm using Yocto, Qt5 is installed via the meta-qt5 layer during the bitbaking of the image

                                jsulmJ 1 Reply Last reply
                                0
                                • E endr

                                  I'm using Yocto, Qt5 is installed via the meta-qt5 layer during the bitbaking of the image

                                  jsulmJ Offline
                                  jsulmJ Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  @endr Well, then I don't know what exactly you need to install. Something with qt and mysql. On Ubuntu it is libqt5sql5-mysql package.

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  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