Installing PostgreSQL on Qt 5.15/PostgreSQL 12/Windows 10
-
Hi,
What likely happened is that you had the 32bit command line activated.
Your approach is the correct one: have all dependencies of the right architecture.
That said, once you have the librairies, the fact that the database itself runs in 32 or 64bit should not be relevant.
One additional thing that you might want to consider is to use an out of source build so you can build as many variation as you want without filling the sources with build artifacts.
You're on the right track !
-
@SGaist said in Installing PostgreSQL on Qt 5.15/PostgreSQL 12/Windows 10:
That said, once you have the librairies, the fact that the database itself runs in 32 or 64bit should not be relevant.
What do you mean by this? What kind of mixing and matching can I do? For example, can I use PostreSQL 12 (only comes in 64bit) for a Qt application that I build as 32bit?
One additional thing that you might want to consider is to use an out of source build so you can build as many variation as you want without filling the sources with build artifacts.
Does this mean somehow specifying "build the plugin and put it in XYZ folder" (as opposed to putting it in
C:\Qt\5.15.0\msvc2019_64\plugins\sqldrivers
or something like that)?Thanks!
-
The server itself could be on a remote machine under a different OS. The client being in 64 or 32 does not have a role. As you noted, it's the client library that you need to build the plugin that needs to match the architecture of your application.
Out of source build means literally that, you trigger the build from a folder outside of the sources. But the steps are the same.
-
@SGaist said in Installing PostgreSQL on Qt 5.15/PostgreSQL 12/Windows 10:
The server itself could be on a remote machine under a different OS. The client being in 64 or 32 does not have a role. As you noted, it's the client library that you need to build the plugin that needs to match the architecture of your application.
The server vs. client part makes sense. What is not clear to me is: can I compile 32bit Qt drivers for PostgreSQL 12 (which is 64bit only)? Since the drivers are compiled from the PostgreSQL source and not the binaries, that should be possible, right?
Thanks!
-
I'm sorry to say I am still having trouble. The compiling the drivers is now fine, but I am having trouble when it comes to actually using them.
From my applications log:
QFactoryLoader::QFactoryLoader() looking at "C:/Qt/5.15.0/msvc2019_64/plugins/sqldrivers/qsqlpsqld.dll" Found metadata in lib C:/Qt/5.15.0/msvc2019_64/plugins/sqldrivers/qsqlpsqld.dll, metadata= { "IID": "org.qt-project.Qt.QSqlDriverFactoryInterface", "MetaData": { "Keys": [ "QPSQL7", "QPSQL" ] }, "archreq": 1, "className": "QPSQLDriverPlugin", "debug": true, "version": 331520 } Got keys from plugin meta data ("QPSQL7", "QPSQL")
So this is the actual debug plugin. The metadata looks good.
Module loaded: C:\Qt\5.15.0\msvc2019_64\plugins\sqldrivers\qsqlpsqld.dll
So it was able to load the DLL for the plugin...
Cannot load library C:\Qt\5.15.0\msvc2019_64\plugins\sqldrivers\qsqlpsqld.dll: The specified module could not be found.
But then failed to load it!
It seems that some deps of qsqlpsqld.dll is failing to load. I checked dependency walker (this rewrite specifically) and
LIBPQ.dll
was missing. This DLL is located inC:\Program Files\PostgreSQL\12\lib
which should have been included (or linked?) when building the plugin!After copying
LIBPQ.dll
to the plugin folder, the following were missing:libcrypto-1_1-x64.dll libssl-1_1-x64.dll libintl-8.dll WS2_32.dll WLDAP32.dll
The first two are from OpenSSL, the last two are from Windows and finally
libintl-8.dll
seems to be from PostgreSQL itself.Here is the
nmake
log (here).I installed OpenSSL (using this installer). Installing this and fixed those two dependencies.
I'm assuming
WS2_32.dll
andWLDAP32.dll
are not causing the issue.So I'm stuck at
libintl-8.dll
: this is a PostreSQL lib, but inC:\Program Files\PostgreSQL\12\lib
all I have islibintl.lib
. My understanding of these things is limited, but I believe thatlibintl.lib
is a static library, so wouldn't the compilation process of the plugin need to generate the above referenced DLL (libintl-8.dll
)? Or where is the reference tolibintl-8.dll
coming from?Is there a way to avoid this hassle altogether by telling
qmake
ornamke
"just build/copy all of the required dependencies to C:\Qt\5.15.0\msvc2019_64\plugins\sqldrivers when you build"? -
@Laplace said in Installing PostgreSQL on Qt 5.15/PostgreSQL 12/Windows 10:
"just build/copy all of the required dependencies to C:\Qt\5.15.0\msvc2019_64\plugins\sqldrivers when you build"?
No, you have to take care for your deps by yourself with e.g. Dependency Walker.
-
@Christian-Ehrlicher said in [Installing PostgreSQL on Qt 5.15/PostgreSQL
No, you have to take care for your deps by yourself with e.g. Dependency Walker.
Good to know at least that I am doing things the right way!
I was able to find
libintl-8.dll
inC:\Program Files\PostgreSQL\12\bin
.Still unable to load the plugin. It seems that
WS2_32.dll
andWLDAP32.dll
are causing issues. These are Windows libraries. Googling reveals pretty generic results. If anyone has any ideas, I'd appreciate the input. -
I would check if the correct msvc runtime is installed on the target pc. Afair it needs the ones from msvc2015. But don't remember exactly.
-
I was able to resolve things!
Here were the required dependencies:
- libcrypto-1_1-x64.dll: from OpenSSL install.
- libssl-1_1-x64.dll: from OpenSSL install.
- libpq.dll: from C:\Program Files\PostgreSQL\12\lib
- libintl-8.dll: from C:\Program Files\PostgreSQL\12\bin
- libiconv-2.dll: from C:\Program Files\PostgreSQL\12\bin
I first copied them manually to the same folder as my .exe, along with the actual plugin DLLs (
qsqlpsql.dll
). That worked.Next I tried using
windqtdeploy
. It actually was able to detect all of them, but it copied them to a folder calledsqldrivers
which is a subdirectory of the folder my .exe is in. That did not work. I had to manually copy the following from thesqldrivers
subdirectory to the main directory:- libpq.dll
- libintl-8.dll
- libiconv-2.dll
Is there any way to tell
windqtdeploy
to copy these DLLs to the .exe folder instead of the subfolder, hence avoiding one more manual step? -
@Laplace said in Installing PostgreSQL on Qt 5.15/PostgreSQL 12/Windows 10:
Is there any way to tell windqtdeploy to copy these DLLs to the .exe folder instead of the subfolder
No but they should be in the same dir as the plugin so it's strange - maybe you have some of those libs (with other version) in your PATH?
-
@Christian-Ehrlicher said in [Installing PostgreSQL on Qt 5.15/PostgreSQL
No but they should be in the same dir as the plugin so it's strange - maybe you have some of those libs (with other version) in your PATH?
I don't think so because (1) I checked my PATH and didn't see anything and (2) I don't have any other versions of PostgreSQL intalled or anything like that.
-
@Laplace Ok, then I'll accept it the way it is - no time to look further why it doesn't work like it should :)
-
-
This did the trick:
#ifdef Q_OS_WIN // Add the sqldrivers folder to path QDir app_dir(QApplication::applicationDirPath()); QString path; path = app_dir.absolutePath(); path = path + "/sqldrivers"; path = QStringLiteral("%1;%2").arg(path).arg(QString(qgetenv("PATH"))); qputenv("PATH", path.toUtf8()); #endif