Static build for SQL plugin



  • Howdy,

    How can I build Qt statically under Windows with -qt-sql-psql parameter (I always get error because of missing Postgresql paths)?

    P.S. I successfully built static edition of Qt with -qt-sql-psql parameter under Ubuntu.


  • Lifetime Qt Champion

    Hi,

    You need to have the dev files from Postgresql installed



  • [quote]You need to have the dev files from Postgresql installed[/quote]
    As I mentioned before I already installed Postgresql so all dev files already exist but Qt can't find the right paths for that files.

    Note:
    "Qt documentation describes":https://qt-project.org/doc/qt-5.1/qtsql/sql-driver.html#qpsql that I've to point to Postgresql dev files during Plugin build but it doesn't mention anything about how to point those paths for static build.


  • Lifetime Qt Champion

    IIRC you just have to add the include and lib path when calling configure (-I and -L)



  • [quote]IIRC you just have to add the include and lib path when calling configure (-I and -L)[/quote]
    May you please give me an example?

    I use the following:
    [code]configure -no-warnings-are-errors -qt-pcre -qt-libpng -ltcg -release -developer-build -static -qt-sql-sqlite -qt-sql-psql -qt-zlib -qt-libjpeg -opengl desktop -nomake examples -nomake tests[/code]

    Postgresql paths:
    [code]C:/PostgreSQL/9.1/include
    C:/PostgreSQL/9.1/lib/libpq.lib[/code]


  • Lifetime Qt Champion

    @
    configure -no-warnings-are-errors -qt-pcre -qt-libpng -ltcg -release -developer-build -static -qt-sql-sqlite -qt-sql-psql -qt-zlib -qt-libjpeg -opengl desktop -nomake examples -nomake tests -I C:/PostgreSQL/9.1/include -L C:/PostgreSQL/9.1/lib/
    @
    And you should be good to go



  • It still gives same error message! nothing changed!
    [code]release_static" -I"." -I"C:\Qt-5.1.0-Static-Win32\qtbase\mkspecs\win32-g++" -o .
    obj\release_static\qsql_psql.o drivers\psql\qsql_psql.cpp
    drivers\psql\qsql_psql.cpp:59:22: fatal error: libpq-fe.h: No such file or direc
    tory
    #include <libpq-fe.h>
    ^
    compilation terminated.
    Makefile.Release:3319: recipe for target '.obj/release_static/qsql_psql.o' faile
    d
    mingw32-make[3]: *** [.obj/release_static/qsql_psql.o] Error 1
    mingw32-make[3]: Leaving directory 'C:/Qt-5.1.0-Static-Win32/qtbase/src/sql'
    Makefile:34: recipe for target 'release' failed
    mingw32-make[2]: *** [release] Error 2
    mingw32-make[2]: Leaving directory 'C:/Qt-5.1.0-Static-Win32/qtbase/src/sql'
    Makefile:207: recipe for target 'sub-sql-make_first' failed
    mingw32-make[1]: *** [sub-sql-make_first] Error 2
    mingw32-make[1]: Leaving directory 'C:/Qt-5.1.0-Static-Win32/qtbase/src'
    makefile:40: recipe for target 'sub-src-make_first' failed
    mingw32-make: *** [sub-src-make_first] Error 2

    C:\Qt-5.1.0-Static-Win32\qtbase>[/code]



  • BTW, I looked for libpq-fe.h manually and I found it in C:/PostgreSQL/9.1/include; So I doubt that -I C:/PostgreSQL/9.1/include -L C:/PostgreSQL/9.1/lib/ are incorrect parameters.


  • Lifetime Qt Champion

    Did you use a capital i for the include line ?



  • [quote]
    Did you use a capital i for the include line ?
    [/quote]
    Yes, I used your suggestion literally


  • Lifetime Qt Champion

    Strange... Try editing the plugin pro file and add the paths there



  • [quote]
    Strange… Try editing the plugin pro file and add the paths there
    [/quote]

    I got same exact result although I start a complete new build!

    C:/Qt/Qt5.1.0-static/qtbase/src/plugins/sqldrivers/psql/psql.pro content

    [code]TARGET = qsqlpsql

    SOURCES = main.cpp
    OTHER_FILES += psql.json
    include(../../../sql/drivers/psql/qsql_psql.pri)

    PLUGIN_CLASS_NAME = QPSQLDriverPlugin
    include(../qsqldriverbase.pri)

    LIBS += -LC:/PostgreSQL/9.1/lib -lpq

    INCLUDEPATH += C:/PostgreSQL/9.1/include
    [/code]


  • Lifetime Qt Champion

    Can you run the configure script with -v to see if something comes up in there ?



  • [quote]
    Can you run the configure script with -v to see if something comes up in there ?
    [/quote]
    There is no such option in configure script!


  • Lifetime Qt Champion

    Sure there is. It's --verbose or -v



  • [quote]
    Sure there is. It’s —verbose or -v
    [/quote]
    This is incorrect, down below you can see the output of configure script!

    [code]C:\Qt\Qt5.1.0-static\qtbase>configure -no-warnings-are-errors -qt-pcre -qt-libpn
    g -ltcg -release -developer-build -static -qt-sql-sqlite -qt-sql-psql -qt-zlib -
    qt-libjpeg -opengl desktop -nomake examples -nomake tests -verbose
    Unknown option ?verbose
    Usage: configure [options]

    Installation options:

    These are optional, but you may specify install directories.[/code]


  • Lifetime Qt Champion

    --verbose with two -



  • [quote]—verbose with two –
    [/quote]
    Still incorrect!

    [code]C:\Qt\Qt5.1.0-static\qtbase>configure -no-warnings-are-errors -qt-pcre -qt-libpn
    g -ltcg -release -developer-build -static -qt-sql-sqlite -qt-sql-psql -qt-zlib -
    qt-libjpeg -opengl desktop -nomake examples -nomake tests --verbose
    Unknown option -?verbose
    Usage: configure [options]

    Installation options:

    These are optional, but you may specify install directories.

    -prefix <dir> ...... This will install everything relative to <dir>[/code]

  • Lifetime Qt Champion

    Then it's not the configure script... It's the configure.exe you are using. Which indeed does not have a verbose output...

    Then check the Makefile generated for the PostgreSql plugin to see if it contains the paths you've added



  • [quote]Then it’s not the configure script… It’s the configure.exe you are using. Which indeed does not have a verbose output…[/quote]
    No, it's the script. Any way to be sure that I called the right script I added .bat (as you can see below); I still get same error!

    [code]C:\Qt\Qt5.1.0-static\qtbase>configure.bat -no-warnings-are-errors -qt-pcre -qt-l
    ibpng -ltcg -release -developer-build -static -qt-sql-sqlite -qt-sql-psql -qt-zl
    ib -qt-libjpeg -opengl desktop -nomake examples -nomake tests --verbose
    Unknown option -?verbose
    Usage: configure [options]

    Installation options:

    These are optional, but you may specify install directories.

    -prefix <dir> ...... This will install everything relative to <dir>[/code]
    

    [quote]Then check the Makefile generated for the PostgreSql plugin to see if it contains the paths you’ve added[/quote]
    I looked into MakeFile where configure.bat exists but I couldn’t find any mentioning to "postgresql" or "psql"

    P.S.

    • May you please take a look to the generated MakeFile and the modified Postgresql .pro file from:
      http://mbnoimi.me/tmp/Makefile
      http://mbnoimi.me/tmp/psql.pro
      I created MakeFile by using:
      [code]C:\Qt\Qt5.1.0-static\qtbase>configure.bat -no-warnings-are-errors -qt-pcre -qt-libpng -ltcg -release -developer-build -static -qt-sql-sqlite -qt-sql-psql -qt-zlib -qt-libjpeg -opengl desktop -nomake examples -nomake tests[/code]
    • Because --verbose option not recognized by configure.bat

  • Lifetime Qt Champion

    The pro file seems ok

    You need to look at the Makefile from the folder of the PostgreSql plugin



  • [quote]You need to look at the Makefile from the folder of the PostgreSql plugin[/quote]
    I couldn’t find Makefile in Postgresql plugin!

    c:/Qt/Qt5.1.0-static/qtbase/src/plugins/sqldrivers/psql content

    @main.cpp
    psql.json
    psql.pro
    psql.pro.user
    README@


  • Lifetime Qt Champion

    The Makefile should have been generated in a subfolder in the build directory



  • [quote]
    The Makefile should have been generated in a subfolder in the build directory
    [/quote]
    Where can I find build directory?



  • BTW, May I suggest to test your suggestions or at least read about them before posting from your memory.
    It seems you're mixing between Windows & Linux configurations.



  • I found this link which it talks about static building but unfortunately it done with Qt4 which isn't work perfectly with Qt5.

    The issue still on how to add Postgresql paths to configure.bat to be able to add them during make process mingw32-make





  • SGaist, thanks a lot for your effort in helping me :)

    Voila, I successfully built Qt statically with Postgresql plugin option as following (it was stupid Windows issue so after formatting Windows the problem solved):
    [code]configure -no-warnings-are-errors -qt-pcre -qt-libpng -ltcg -release -developer-build -static -qt-sql-sqlite -qt-sql-psql -qt-zlib -qt-libjpeg -opengl desktop -nomake examples -nomake tests -I C:/PostgreSQL/9.1/include -L C:/PostgreSQL/9.1/lib/[/code]

    But Qt it self coudln't link pg libratry for usual Qt projects. In the following .pro of test project uses QPSQL:

    [code]QT += core sql

    QT -= gui

    TARGET = TestSSLConnection
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp

    win32 {
    LIBS += -LC:/PostgreSQL/9.1/lib -lpg
    PRE_TARGETDEPS += C:/PostgreSQL/9.1/lib/pq.lib
    QMAKE_LFLAGS += -static -static-libgcc -static-libstdc++ -lpthread
    }[/code]

    It generates the following error on building process:
    [code]mingw32-make[1]: Leaving directory 'F:/build-TestSSLConnection-Satic_postgresql-Release'
    mingw32-make[1]: *** No rule to make target 'C:/PostgreSQL/9.1/lib/pq.lib', needed by 'release\TestSSLConnection.exe'. Stop.
    makefile:34: recipe for target 'release' failed
    mingw32-make: *** [release] Error 2
    16:08:31: The process "C:\Qt\Qt5.1.1\Tools\mingw48_32\bin\mingw32-make.exe" exited with code 2.
    Error while building/deploying project TestSSLConnection (kit: Satic-postgresql)
    When executing step 'Make'
    16:08:31: Elapsed time: 00:14.[/code]

    How can I fix this issue?



  • BTW, Do I've to use libpq.lib OR pq.lib in:
    [code]PRE_TARGETDEPS += C:/PostgreSQL/9.1/lib/pq.lib[/code]

    OR

    [code]PRE_TARGETDEPS += C:/PostgreSQL/9.1/lib/libpq.lib[/code]


  • Lifetime Qt Champion

    You should not need the PRE_TARGETDEPS in this case (unless you are working on the postgresql library and generating the static library yourself)



  • [quote]You should not need the PRE_TARGETDEPS in this case[/quote]
    I commented this related line(s) but I still get an error!
    [code]QT += core sql

    QT -= gui

    TARGET = TestSSLConnection
    CONFIG += console
    CONFIG -= app_bundle

    TEMPLATE = app

    SOURCES += main.cpp

    win32 {
    LIBS += -LC:/PostgreSQL/9.1/lib -lpg

    PRE_TARGETDEPS += C:/PostgreSQL/9.1/lib/pq.lib

    QMAKE_LFLAGS += -static -static-libgcc -static-libstdc++ -lpthread
    

    }[/code]

    [code]g++ -static -static-libgcc -static-libstdc++ -lpthread -Wl,-s -Wl,-subsystem,console -mthreads -o release\TestSSLConnection.exe release/main.o -LC:/PostgreSQL/9.1/lib -lpg -LC:/Qt/Qt5.1.1-static-sqlite-pgsql/qtbase/lib -lQt5Sql -lpq -lQt5Core -lole32 -luuid -lws2_32 -ladvapi32 -lshell32 -luser32 -lkernel32
    c:/qt/qt5.1.1/tools/mingw48_32/bin/../lib/gcc/i686-w64-mingw32/4.8.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lpg
    Makefile.Release:77: recipe for target 'release\TestSSLConnection.exe' failed
    mingw32-make[1]: Leaving directory 'F:/Snippets/build-TestSSLConnection-Static_pg2-Release'
    makefile:34: recipe for target 'release' failed
    c:/qt/qt5.1.1/tools/mingw48_32/bin/../lib/gcc/i686-w64-mingw32/4.8.0/../../../../i686-w64-mingw32/bin/ld.exe: cannot find -lpq
    collect2.exe: error: ld returned 1 exit status
    mingw32-make[1]: *** [release\TestSSLConnection.exe] Error 1
    mingw32-make: *** [release] Error 2
    12:27:50: The process "C:\Qt\Qt5.1.1\Tools\mingw48_32\bin\mingw32-make.exe" exited with code 2.
    Error while building/deploying project TestSSLConnection (kit: Static-pg2)
    When executing step 'Make'
    12:27:50: Elapsed time: 00:24.[/code]


  • Lifetime Qt Champion

    Are you sure that your Postgresql install is a mingw build ?



  • [quote]
    Are you sure that your Postgresql install is a mingw build ?
    [/quote]
    I'm not sure what if Postgresql built by MinGW but I'm using the official installer of Postgresql (postgresql-9.1.3-1-windows.exe)



  • Guys this thread took a long discussion. Does any one built Qt statically with one of SQL plugins (except sqlite)?


  • Moderators

    [quote author="mbnoimi" date="1379676626"]Guys this thread took a long discussion. Does any one built Qt statically with one of SQL plugins (except sqlite)?[/quote]

    When your postgresql plugin isn't built with the same compiler it maybe that i can't load the symbols from the DLL.
    Thus to make sure you can try to build it yourself and retry it then.
    Read "this":https://wiki.postgresql.org/wiki/Building_With_MinGW and "this":http://qt-project.org/forums/viewthread/16639.


  • Lifetime Qt Champion

    Also, don't forget the licensing issues with static linking to Qt "explanation here":http://www.slideshare.net/qtbynokia/qt-licensing-explained



  • [quote author="raven-worx" date="1379677488"]Thus to make sure you can try to build it yourself and retry it then.
    Read "this":https://wiki.postgresql.org/wiki/Building_With_MinGW and "this":http://qt-project.org/forums/viewthread/16639.

    [/quote]

    I followed up the pointed wiki page by downloading Postgresql from "this link":http://ftp.postgresql.org/pub/source/v9.1.9/postgresql-9.1.9.tar.bz2 then used the following options:

    [code]$ ./configure --without-zlib --with-openssl --with-includes=C:/OpenSSL-Win32/include --with-libraries=C:/OpenSSL-Win32/lib
    /MinGW [/code]

    but I got error during configure process:
    [code]checking openssl/ssl.h usability... no
    checking openssl/ssl.h presence... no
    checking for openssl/ssl.h... no
    configure: error: header file <openssl/ssl.h> is required for OpenSSL [/code]

    Do you've an idea how to fix this issue?

    P.S. "Some guy faced it before":http://web.archiveorange.com/archive/v/V95x82sNS8lCeW2yiGEY but he couldn't find any response :(


  • Lifetime Qt Champion

    Are you sure the --with-includes and --with-libraries options are valid ? AFAIK it should be -I and -L when calling configure



  • [quote author="SGaist" date="1379794681"]Are you sure the --with-includes and --with-libraries options are valid ? AFAIK it should be -I and -L when calling configure[/quote]

    AFAIK these two options used in Postgresql configure file while -l -L used for Qt.

    Any way, I'll try to use -l & -L to se if they will affect or not.



  • [quote]Are you sure the —with-includes and —with-libraries options are valid ? AFAIK it should be -I and -L when calling configure
    [/quote]
    I tried to use -l & -L as you mentioned above but I got this error message. It seems that --with-libraries & --with-includes are the correct options:

    [code]mbnoimi@MBNOIMI-VBOX ~/postgresql-9.1.9
    $ ./configure --without-zlib --with-openssl -lC:/OpenSSL-Win32/include -LC:/OpenSSL-Win32/lib/MinGW
    configure: error: unrecognized option: -lC:/OpenSSL-Win32/include
    Try `./configure --help' for more information.

    mbnoimi@MBNOIMI-VBOX ~/postgresql-9.1.9[/code]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.