View Full Version : Want a static database plugin - tried a lot but have still DLL dependecies.

22nd February 2007, 10:09

I want to distribute one executable file of my application which should be able to connect to a PostgreSQL database. After I did spend hours on compiling a static version of Qt I hoped that I can get one executables which has no external dependencies on any DLL.

So that's what I did so far:

1. As descripted in this article (http://wiki.qtcentre.org/index.php?title=Building_static_Qt_on_Windows) I changed the VS environmet to be able to create static Qt.


configure -static -platform win32-msvc.net -qt-sql-psql -I C:\Programme\PostgreSQL\8.1\include -L C:\Programme\PostgreSQL\8.1\lib\ms

After that I did run

nmake sub-src

I thought that the nmake process will create a static version of the qsql plugin!!

3. I changed the main function of my project and added the following lines:

#include <QtPlugin>


The tool compiled succesfull without any errors. After that I checked the dependencies of my new executable and saw that it refers to the LIBPQ.DLL which, of course, refers to some other DLLs, too.

Is there anything I have to change for a static version of my tool. I do not want these dependencies to the libpq.dll.

Any suggestions.

Thanks in advance.

22nd February 2007, 10:25
You have to compile/download a static version of the postgresql client library (libpq.dll) and probably all its dependencies as well (and then recompile the postgresql plugin in static mode)... Just for the record - it doesn't have anything to do with Qt itself :)

22nd February 2007, 11:04

but I thought that this is what I did since I started configure with the -static option.
I have libpq.lib as external lib defined in VS so it binds against the static lib, right?
So why is there a need for the postgres DLLs?

Could you please provide a step by step instruction?

Thanks in advance,

22nd February 2007, 11:34
but I thought that this is what I did since I started configure with the -static option.
You only asked to compile Qt statically using available libraries. And the only pq lib available is the one compiled in shared mode.

A static lib of what?
[quote]So why is there a need for the postgres DLLs?
Do you have a static postgres library?

Could you please provide a step by step instruction?

First try downloading a static libpq from the Internet. Othewise you'd have to recompile postgres.

22nd February 2007, 15:20

thank you for that hint. It's working now and my app is static.

Great - that's what I want.

Thanks again.

16th September 2007, 20:55
I have similar problem with mingw32.

1. I've configured and made qt statically:

@echo off

set LIB=
set QTDIR=C:\Qt\4.3.1
set PATH=C:\Qt\4.3.1\bin
set PATH=%PATH%;C:\MinGW\bin
set PATH=%PATH%;%SystemRoot%\System32
set QMAKESPEC=win32-g++
set PGDIR=C:\Progra~1\PostgreSQL\8.2

cd %QTDIR%
REM make confclean
configure -release -static -no-qt3support -no-rtti -no-stl -no-exceptions -no-accessibility -qt-libpng -qt-sql-psql -I %PGDIR%\include -L %PGDIR%\lib -l libpq
REM cd %QTDIR%\src
REM qmake
mingw32-make release

2. After succesfull compilation (like given below):

g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -Wl,-subsystem,windows -o "release\sigs_tk.exe" object_script.sigs_tk.Release -L"c:\Qt\4.3.1\lib" -lmingw32 -lqtmain -lversion -lQtSql -lQtGui -lQtCore -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lwinspool -lmsimg32 -lQtCore4 -lkernel32 -luser32 -lshell32 -luuid -lole32 -ladvapi32 -lws2_32 -L"C:\Progra~1\PostgreSQL\8.2\lib" -lpq

I still have "LIBPQ.DLL" in dependencies.

Where is my missing?

Note: libpq.a file in C:\Progra~1\PostgreSQL\8.2\lib dir is 96 kb.

16th September 2007, 22:29
Delete or rename the libpq.dll for the time of compilation so that the dll doesn't come before the static version of the library.

17th September 2007, 07:27
renamed all libpq.dll after full search on all drives - still the same. + libpq.a placed to "lib folder of Qt - the same. Now in dependencies "LIBPQ" marked with "?" sign (means - can't be found in any location).

So, may my "libpq.a" be just a wrapper for libpq.dll? If so - how can I get real, static libpq.a? Second variant of libpq.a - built from sources (first was found in lib folder after win32-installer). Second variant gives the same result.

17th September 2007, 10:01
Well, obviously you need a static library for PostgreSQL installed. You should probably visit www.postgresql.org and search for info on obtaining a static client library there. 96kB for libpq doesn't seem correct.

17th September 2007, 14:04
In documentation regarding Win32 (http://www.postgresql.org/docs/8.2/interactive/install-win32.html) there are remarked that after building we will have following binaries:

The dynamically linkable frontend library

Import library to link your programs to libpq.dll

Static version of the frontend library

And I really got them (libpq.lib - 323Kb, pibpq.dll - 104Kb, libpqdll.lib - 26,6Kb)

There is nothing remarked about MinGW installation. But after building with MingW I have got libpq.dll (size 149Kb) and libpq.a (size 96Kb).

There should be some undocumented way of how to get real static libpq.a using MinGW...

17th September 2007, 14:58
Try forcing a link to libpq.a by adding it to the LIBS variable like so:

LIBS+= /path/to/libpq.a (without "-l" at the beginning)

17th September 2007, 18:27
LIBS+= /path/to/libpq.a (without "-l" at the beginning)
I've copied libpq.a to C:\mingw\lib. Your slution produces:

g++ -enable-stdcall-fixup -Wl,-enable-auto-import -Wl,-enable-runtime-pseudo-reloc -Wl,-s -Wl,-subsystem,windows -o "release\sigs_tk.exe" object_script.sigs_tk.Release -L"c:\Qt\4.3.1\lib" -lmingw32 -lqtmain C:\mingw\lib\libpq.a -lversion -lQtSql -lQtGui -lQtCore -lgdi32 -lcomdlg32 -loleaut32 -limm32 -lwinmm -lwinspool -lmsimg32 -lQtCore4 -lkernel32 -luser32 -lshell32 -luuid -lole32 -ladvapi32 -lws2_32

and fails with lot of errors:

c:\Qt\4.3.1\lib/libQtSql.a(qsql_psql.o)(.text+0x19):qsql_psql.cpp: undefined reference to `PQerrorMessage'
c:\Qt\4.3.1\lib/libQtSql.a(qsql_psql.o)(.text+0x18c):qsql_psql.cpp : undefined reference to `PQresultStatus'
c:\Qt\4.3.1\lib/libQtSql.a(qsql_psql.o)(.text+0x28f):qsql_psql.cpp : undefined reference to `PQntuples'
c:\Qt\4.3.1\lib/libQtSql.a(qsql_psql.o)(.text+0x494):qsql_psql.cpp : undefined reference to `PQclear'
c:\Qt\4.3.1\lib/libQtSql.a(qsql_psql.o)(.text+0x5e4):qsql_psql.cpp : undefined reference to `PQntuples'
c:\Qt\4.3.1\lib/libQtSql.a(qsql_psql.o)(.text+0x622):qsql_psql.cpp : undefined reference to `PQnfields'
c:\Qt\4.3.1\lib/libQtSql.a(qsql_psql.o)(.text+0x67e):qsql_psql.cpp : undefined reference to `PQftype'

Inserting "-LIBS+= C:\mingw\lib\libpq.a" directly to makefile fails with same errors.

18th September 2007, 12:17
Are you sure the .a file is actually the library you're looking for?

18th September 2007, 18:44
I hope - yes. I don't see any other variants

18th September 2007, 19:36
Hope is not what I expected. Could you verify that?

18th September 2007, 20:41
how can I verify it? All pages I've found in internet so far say that libpq.a file is an analog of libpq.lib file. First is for gcc compilation, while second is for VS. There are no other possible libraries. On hundred forums in internet peoples compiling applications with just -lpq parameter and everything works. It really works, but depends on libpq.dll file and cannot be launched without it (noone remarks it in posts btw).

What have I found so far: libpq.a "pseudo-static" library is needed by QtSql module. Without libpq compilation finishes on QtSql linking stage. So, libpq is needed by QtSql only.

One interesting experimental fact - when linking QtSql4 (instead of QtSql) without specifing libpq -compilation finishes without errors! But after launching compiled application "PQSQL driver not found" errors appear.

19th September 2007, 07:06
Problem solved. To build real static libpq.a you need specify undocumented key "enable_shared=no". It's ~1.5 times bigger (156Kb) then "pseudo-static" libpq.a (97Kb)

19th September 2007, 10:12
So that was just an import library after all.

20th September 2007, 09:14
btw, the bug (or feature?) of libpq.a building still exists (that's why my problem occured). Maybe it can be useful for someone.

Here is description. You will never get real static libpq.a if you have done building of shared version of libpq before. You MUST delete pseudo-static libpq.a before building real static libpq.a

Folder "\src\interfaces\libpq\":
Here is failure scenario:
1. make install (dynamic libpq.dll and pseudo-static libpq.a were created)
2. make install enable_shared=no (get real static libpq.a - fails).
Real static libpq.a wasn't created. Insted of it we can see old, pseudo-static libpq.a.

Another failure scenario:
1. make install enable_shared=no (real static libpq.a was created - indeed).
2. make install (dynamic libpq.dll and pseudo-static libpq.a were created).
Real static libpq.a was overwritten by pseudo-static libpq.a!

Here is successfull, working scenario:
1. make install (dynamic libpq.dll and pseudo-static libpq.a were created).
2. delete pseudo-static libpq.a.
3. make install enable_shared=no (get real static libpq.a).
So that's only possible way to get both shared and real static libpq libraries.

Strange, why pseudo-static libp.q can overwrite real static one but can't vice-versa?

I think lot of bugs peoples have with libpq are based on that bug...

20th September 2007, 11:56
It's neither a bug nor a feature. It's just the way make works. Basically if you change configuration options you should always issue "make clean" afterwards (or "before" in that case).