table des matières
  1. Trouble
  2. Trouble shooting
    1. Compiler les drivers
    2. Vérification

En cmake svp.

Trouble

QSqlDatabase: QMYSQL driver not loaded
QSqlDatabase: available drivers: QSQLITE QMYSQL QMYSQL3 QODBC QODBC3 QPSQL QPSQL7
ldd /opt/Qt/6.1.0/gcc_64/plugins/sqldrivers/libqsqlmysql.so
    linux-vdso.so.1 (0x00007ffc19f62000)
	**libmysqlclient.so.21 => not found**
	libQt6Sql.so.6 => /softs/Qt/6.1.3/gcc_64/plugins/sqldrivers/./../../lib/libQt6Sql.so.6 (0x00007fd68ec66000)
	libQt6Core.so.6 => /softs/Qt/6.1.3/gcc_64/plugins/sqldrivers/./../../lib/libQt6Core.so.6 (0x00007fd68e668000)

Trouble shooting

Dans le CmakeList.txt

find_package(QT NAMES Qt6 Qt5 COMPONENTS Core REQUIRED)
find_package(Qt${QT_VERSION_MAJOR} COMPONENTS Core REQUIRED)
find_package(Qt6 COMPONENTS Sql REQUIRED)

add_executable(bdd2
  main.cpp
)
target_link_libraries(bdd2 Qt${QT_VERSION_MAJOR}::Core Qt6::Sql)

Pour la config du poste,

  • installer les packages suivants :

Pour debian 10

  sudo apt install default-libmysqlclient-dev mysql-common libmariadb-dev libmariadb-dev-compat  libmariadb3 mariadb-client-10.3
  mariadb-client mariadb-client-core-10.3 mariadb-common libssl-dev

Pour debian 11

  sudo apt install default-libmysqlclient-dev mysql-common libmariadb-dev libmariadb-dev-compat  libmariadb3 mariadb-client-10.5
  mariadb-client mariadb-client-core-10.5 mariadb-common libssl-dev
  • Installer les src de Qt via Qt maintenance.bundle update

  • Aller dans le répertoires des sources des drivers sql

cd /opt/Qt/6.1.0/Src/qtbase/src/plugins/sqldrivers

Compiler les drivers

  • Option : Debian 10 - Modifier le script qt-cmake

    original_cmake_path="/opt/Qt/Tools/CMake/bin/cmake"
    
sudo /opt/Qt/6.1.0/gcc_64/bin/qt-cmake
sudo /opt/Qt/Tools/CMake/bin/cmake --build .
sudo /opt/Qt/Tools/CMake/bin/cmake --install .

Attention : ne pas oublier le point à la fin des instructions précédentes…

Vérification

  • La sortie de ldd montre que le driver mariadb est up
 ldd /opt/Qt/6.1.0/gcc_64/plugins/sqldrivers/libqsqlmysql.so 
	linux-vdso.so.1 (0x00007ffca95b0000)
	**libmariadb.so.3 => /lib/x86_64-linux-gnu/libmariadb.so.3 (0x00007f1ff2c35000)**
	libQt6Sql.so.6 => /softs/Qt/6.1.3/gcc_64/plugins/sqldrivers/./../../lib/libQt6Sql.so.6 (0x00007f1ff2be4000)