Can't load sql drivers when configuring and building Qt 6.8.1 from source on linux/Ubuntu 24.04.1
-
The Problem
In a fresh Ubuntu installation, I successfully built & installed PostgreSQL, Qt & Qt Creator from source. When I run my app and try to connect to the database, I get the following error:
qt.sql.qsqldatabase: QSqlDatabase: QPSQL driver not loaded qt.sql.qsqldatabase: QSqlDatabase: available drivers: QSQLITE
From my investigation, it appears that only the default sqlite driver is loading. Numerous attempts to use the -sql-driver configure option to build the other drivers have failed. I believe the issue is with the Qt build. The PostgreSQL & QT Creator information is included for context. I am new to this and need help. What am I missing? Surely it's something simple, right?
The Environment
- Building for: linux-g++ (x86_64, CPU features: )
- Compiler: gcc 13.2.0
- fresh Ubuntu 24.04.1 LTS installation
- build & install PostgreSQL "T REL_17_2" from source
- build & install Qt "T v6.8.1" from source
- build & install Qt Creator "R origin/15.0" from source
Source & Build Directories & PATH
/usr/local/src/_postgresql (build) /usr/local/src/postgresql (src) /usr/local/src/_qt (build) /usr/local/src/qt (src) /usr/local/src/_qt_creator (build) /usr/local/src/qt_creator (src) echo $PATH /the usual defaults: /usr/local/postgresql/17.2/bin: /usr/local/postgresql/17.2/lib: /usr/local/ninja/1.12.1: /usr/local/qt/6.8.1/bin: /usr/local/qt/6.8.1/lib: /usr/local/qt_creator/o15.0/bin
The Guides I Used
- https://wiki.qt.io/Building_Qt_6_from_Git
- https://doc.qt.io/qt-6/getting-sources-from-git.html
- https://doc.qt.io/qt-6/linux-building.html
- https://doc.qt.io/qt-6/sql-driver.html
- https://wiki.qt.io/Building_Qt_Creator_from_Git
- https://github.com/qt-creator/qt-creator/blob/master/README.md
- https://wiki.qt.io/Building_Qt_Creator_from_Git_on_Ubuntu_22.04***
*** I couldn't get everything to build until I installed the dependencies mentioned in this guide. I don't know which package(s) I needed, but it worked. I didn't use the commands, simply installed the dependencies.
Steps to Re-Create
clone qt from git into the source directory /src/qt/ (I can't remember the command I used but I cloned the entire tree and then checked out Tag 6.8.1)
run configure from within the build directory /src/_qt/ WITHOUT -sql option
../qt/configure -init-submodules -prefix /usr/local/qt/6.8.1
relevant portion of configure output without -sql-<driver> option
-- Checking dependencies of submodule 'qtwebview' -- Configuring submodule 'qtbase' -- [QtBase] Setting build type to 'Release' as none was specified. -- Configuring submodule 'qtimageformats'
and
-- Configuring done (56.1s) -- Generating done (3.0s) -- Build files have been written to: /usr/local/src/_qt
relevant portion of resulting config.summary
Qt Sql Drivers: DB2 (IBM) .............................. no InterBase .............................. no MySql .................................. no OCI (Oracle) ........................... no ODBC ................................... no PostgreSQL ............................. no SQLite ................................. yes Using system provided SQLite ......... no Mimer .................................. no
successfully clone, configure, build & install Qt Creator from source
build & run myApp, attempt database connection using psql driver with the following error message:
The Error Message
The program output with QT_DEBUG_PLUGINS=1 runtime variable:
qt.core.plugin.factoryloader: checking directory path "/usr/local/qt/6.8.1/plugins/sqldrivers" ... qt.core.plugin.factoryloader: looking at "libqsqlite.so" qt.core.plugin.loader: Found metadata in lib /usr/local/qt/6.8.1/plugins/sqldrivers/libqsqlite.so, metadata= { "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface", "MetaData": { "Keys": [ "QSQLITE" ] }, "archlevel": 1, "className": "QSQLiteDriverPlugin", "debug": false, "version": 395264 } qt.core.plugin.factoryloader: Got keys from plugin meta data QList("QSQLITE") qt.core.plugin.factoryloader: checking directory path "/home/kingwm/src/kco_app7/build/Desktop-Debug/sqldrivers" ... qt.sql.qsqldatabase: QSqlDatabase: QPSQL driver not loaded qt.sql.qsqldatabase: QSqlDatabase: available drivers: QSQLITE Error opening database: QSqlError("", "Driver not loaded", "Driver not loaded")
Upon Further Investigation
The contents of the source directory (all drivers):
root@****:/usr/local/src# ls /usr/local/src/qt/qtbase/src/plugins/sqldrivers CMakeLists.txt configure.cmake db2 ibase mimer mysql oci odbc psql qt_cmdline.cmake README sqlite
The contents of the resultant installation directory (one driver.so):
root@****:/usr/local/src/_qt# ls /usr/local/qt/6.8.1/plugins/sqldrivers libqsqlite.so
It seems only the default sqlite driver is being loaded. At this point, I discovered the guide on sql drivers and tried to build the program with the -sql-driver option.
from the build directory /src/_qt/, view the man page for configure:
../qt/configure --help
partial output from --help
+ /usr/local/src/qt/qtbase/configure -top-level -help Usage: configure [options] [-- cmake-options] This is a convenience script for configuring Qt with CMake. Options after the double dash are directly passed to CMake. You can pass CMake variables as configure arguments: configure VAR=value which is equivalent to configure -- -DVAR=value Conventions for the remaining options: When an option's description is followed by a list of values in brackets, the interpretation is as follows: 'yes' represents the bare option; all other values are possible prefixes to the option, e.g., -no-gui. Alternatively, the value can be assigned, e.g., --gui=yes. Values are listed in the order they are tried if not specified; 'auto' is a shorthand for 'yes/no'. Solitary 'yes' and 'no' represent binary options without auto-detection. Database options: -sql-<driver> ........ Enable SQL <driver> plugin. Supported drivers: db2 ibase mysql oci odbc psql sqlite mimer [all auto] -sqlite .............. Select used sqlite [system/qt]
I really want all drivers, or at least mysql, odbc & psql but can't figure out the [all auto] convention from the --help page. I tried all these combinations, got various error messages and tried to learn from them. (I know, silly me, I am new to this and have all the time in the world and no sleep requirements) -sql-psql -sql-auto -sql -sql-[psql mysql odbc] -all-sql -sql=all --sql=all -sql=all -sql-all -all-sql -all-sql-psql -sql-mysql -sql- -sql-psql=yes --sql-psql=yes --sql=yes.
In the end, using "-sql-psql" and "-sql-psql -sql-mysql -sql-odbc" appear to be correct syntax, but they all produce the driver not loaded error.
To keep it simple, I ran configure from within the build directory /src/_qt/ again, this time using the -sql-psql option, but WITHOUT first deleting the build directory and starting over with an empty directory.
../qt/configure -init-submodules -prefix /usr/local/qt/6.8.1 -sql-psql
The configure script finishes with a new warning: (that that PostgreSQL is not found and there are only warnings issued)
-- Checking dependencies of submodule 'qtwebview' -- Configuring submodule 'qtbase' -- [QtBase] CMAKE_BUILD_TYPE was already explicitly set to: 'Release' [QtBase] 'sql_psql' was changed from OFF to ON CMake Warning at qtbase/cmake/QtFeature.cmake:896 (message): Due to detected feature set changes, dependent features will be re-computed automatically. This might cause a lot of files to be rebuilt. To disable this behavior, configure with -DQT_NO_FEATURE_AUTO_RESET=ON Call Stack (most recent call first): qtbase/cmake/QtBuildHelpers.cmake:472 (qt_internal_detect_dirty_features) qtbase/cmake/QtBuild.cmake:4 (qt_internal_setup_build_and_global_variables) qtbase/cmake/QtSetup.cmake:6 (include) qtbase/cmake/QtBuildRepoHelpers.cmake:21 (include) qtbase/cmake/QtBuildRepoHelpers.cmake:232 (qt_build_internals_set_up_private_api) qtbase/cmake/QtBaseHelpers.cmake:154 (qt_build_repo_begin) qtbase/CMakeLists.txt:32 (qt_internal_qtbase_build_repo) CMake Warning at qtbase/cmake/QtFeature.cmake:285 (message): Resetting 'FEATURE_sql_psql' from 'ON' to 'OFF' because it doesn't meet its condition after reconfiguration. Condition expression is: 'PostgreSQL_FOUND' Call Stack (most recent call first): qtbase/cmake/QtFeature.cmake:434 (qt_feature_check_and_save_user_provided_value) qtbase/cmake/QtFeature.cmake:711 (qt_evaluate_feature) qtbase/src/plugins/sqldrivers/CMakeLists.txt:44 (qt_feature_module_end) -- Configuring submodule 'qtimageformats'
and the script finishes without any errors, only warnings
-- Configuring done (43.7s) -- Generating done (2.9s) -- Build files have been written to: /usr/local/src/_qt
relevant portion of resulting config.summary
Qt Sql Drivers: DB2 (IBM) .............................. no InterBase .............................. no MySql .................................. no OCI (Oracle) ........................... no ODBC ................................... no PostgreSQL ............................. no SQLite ................................. yes Using system provided SQLite ......... no Mimer .................................. no
You can see PostgreSQL isn't loaded. With the error, I didn't bother building and installing this configuration. Next, I deleted the build folder and started from scratch, again, this time using the -sql-psql option and with a clean build directory.
../qt/configure -init-submodules -prefix /usr/local/qt/6.8.1 -sql-psql
The configure script behaved differently this time. The warning message changed and the script exited in error at the end.
-- Checking dependencies of submodule 'qtwebview' -- Configuring submodule 'qtbase' -- [QtBase] Setting build type to 'Release' as none was specified. CMake Error at qtbase/cmake/QtBuildInformation.cmake:534 (message): Feature "sql_psql": Forcing to "ON" breaks its condition: PostgreSQL_FOUND Condition values dump: PostgreSQL_FOUND = "FALSE" Call Stack (most recent call first): qtbase/cmake/QtFeature.cmake:322 (qt_configure_add_report_error) qtbase/cmake/QtFeature.cmake:442 (qt_feature_check_and_save_internal_value) qtbase/cmake/QtFeature.cmake:711 (qt_evaluate_feature) qtbase/src/plugins/sqldrivers/CMakeLists.txt:44 (qt_feature_module_end) -- Configuring submodule 'qtimageformats'
and finally
ERROR: Feature "sql_psql": Forcing to "ON" breaks its condition: PostgreSQL_FOUND Condition values dump: PostgreSQL_FOUND = "FALSE" CMake Error at qtbase/cmake/QtBuildInformation.cmake:220 (message): Check the configuration messages for an error that has occurred. Call Stack (most recent call first): qtbase/cmake/QtBuildInformation.cmake:39 (qt_configure_print_summary) qtbase/cmake/QtBaseTopLevelHelpers.cmake:88 (qt_print_feature_summary) qtbase/cmake/QtBaseTopLevelHelpers.cmake:76 (qt_internal_print_top_level_info) CMakeLists.txt:120 (qt_internal_top_level_end) -- Configuring incomplete, errors occurred! CMake Error at /usr/local/src/qt/qtbase/cmake/QtProcessConfigureArgs.cmake:1139 (message): CMake exited with code 1. CMake Error at /usr/local/src/qt/cmake/QtIRProcessHelpers.cmake:173 (message): /usr/local/src/qt/qtbase/configure -top-level -prefix /usr/local/qt/6.8.1 -sql-psql exited with status: 1 Call Stack (most recent call first): /usr/local/src/qt/cmake/QtTopLevelHelpers.cmake:35 (qt_ir_execute_process_and_log_and_handle_error) /usr/local/src/qt/cmake/QtTopLevelHelpers.cmake:57 (qt_tl_run_toplevel_configure) /usr/local/src/qt/cmake/QtTopLevelConfigureScript.cmake:17 (qt_tl_run_main_script)
Here is the relevant part of config.summary. Note that PostgreSQL is now yes, in spite of the errors.
Qt Sql Drivers: DB2 (IBM) .............................. no InterBase .............................. no MySql .................................. no OCI (Oracle) ........................... no ODBC ................................... no PostgreSQL ............................. yes SQLite ................................. yes Using system provided SQLite ......... no Mimer .................................. no
That is as far as I have been able to get. What am I missing?
-
@jsulm I don't understand. I installed PostgreSQL from source. Might installing those packages interfere with my PG installation? Also, someone else mentioned that, so I checked and according to Google, I should reconfigure my PG building to include all the developer stuff. I wanted to build PostgreSQL, pgAmin, Qt & Qt Creator from source. If I can build the dev libs from source, I would rather do that.
This note here from the docs?
https://doc.qt.io/qt-6/sql-driver.html
Note: To build a driver plugin you need to have the appropriate client library for your Database Management System (DBMS). This provides access to the API exposed by the DBMS, and is typically shipped with it. Most installation programs also allow you to install "development libraries", and these are what you need. These libraries are responsible for the low-level communication with the DBMS. Also make sure to install the correct database libraries for your Qt architecture (32 or 64 bit). -
Why did you compile postgresql by yourself? Simply use the ones from your distro...
Where did you install postgresql to? If it's a non-default location you have to pass this to configure in a clean build dir. -
For practice. I installed PG from source, and all the others, because I wanted to learn how. Plus, I get a little more control over the specific version I use. I am setting up for a long term project and these are skills I need to learn.
PostgreSQL is installed here, and I do have it on the $PATH, but I guess the compiler is not checking the path?
/usr/local/postgresql/17.2/bin:
/usr/local/postgresql/17.2/lib: -
Hi,
PATH has nothing to do with library discovery. You're working on Linux, not Windows.
Use the -L argument to add additional paths to configure.On a side note, stop working as root. There's no need for that for any build activity.
-
@SGaist I set the path variable because it is mentioned several times in the various docs I have read. I don't know if it is useful in this scenario or not.
I used -L arguments to pass the include and lib directories.
/usr/local/postgresql/17.2/include /usr/local/postgresql/17.2/lib
In a new error message, it complained it couldn't find Ninja, so I added my Ninja path.
/usr/local/ninja/1.12.1
I am using sudo because nothing will work unless I use it. I presume it is because the source, build and install directories are all in /usr/local/.
I ran the following command, it fails with the same Postgres not found error.
../qt/configure -init-submodules -prefix /usr/local/qt/6.8.1 -sql-psql -L /usr/local/postgresql/17.2/lib -I /usr/local/postgresql/17.2/include -- -DCMAKE_BUILD_TYPE=Release -DCMAKE_GENERATOR=Ninja /usr/local/ninja/1.12.1
But when I run it WITHOUT the -sql-psql option, configure completes successfully with a few warnings. One is that it ignored the the path i provided for Ninja. Again, Ninja is on the path, but if it ignores that path I provide, I don't know how it is finding Ninja unless a sub-routine is providing it.
+ /usr/local/src/qt/qtbase/configure -top-level -prefix /usr/local/qt/6.8.1 -L /usr/local/postgresql/17.2/lib -I /usr/local/postgresql/17.2/include -- -DCMAKE_BUILD_TYPE=Release -DCMAKE_GENERATOR=Ninja /usr/local/ninja/1.12.1 '/usr/bin/cmake' '-DCMAKE_BUILD_TYPE=Release' '-DCMAKE_GENERATOR=Ninja' '/usr/local/ninja/1.12.1' '-DQT_INTERNAL_CALLED_FROM_CONFIGURE:BOOL=TRUE' '-DCMAKE_INSTALL_PREFIX=/usr/local/qt/6.8.1' '-DQT_EXTRA_INCLUDEPATHS=/usr/local/postgresql/17.2/include' '-DQT_EXTRA_LIBDIRS=/usr/local/postgresql/17.2/lib' '-G' 'Ninja' '/usr/local/src/qt' CMake Warning: Ignoring extra path from command line: "/usr/local/ninja/1.12.1" -- The CXX compiler identification is GNU 13.3.0 -- The C compiler identification is GNU 13.3.0
-
Pass PostgreSQL_ROOT as written in the documentation: https://doc.qt.io/qt-6/sql-driver.html#how-to-build-the-qpsql-plugin-on-unix-and-macos
-
@Christian-Ehrlicher said in Can't load sql drivers when configuring and building Qt 6.8.1 from source on linux/Ubuntu 24.04.1:
Pass PostgreSQL_ROOT as written in the documentation: https://doc.qt.io/qt-6/sql-driver.html#how-to-build-the-qpsql-plugin-on-unix-and-macos
My bad for the -L pointer ! Old Qt 5 habits.
@Christian-Ehrlicher is correct.
As for the sudo requirements, it's still wrong. The fact that you have stuff in /usr/local should have no influence unless there's a in issue with the files permissions that should be fixed.
As for PATH, it's only used to find executables on Linux, it has nothing to do with libraries.