Qt6 topics merged with General

Building Static Qt

  • Hi, I wanted to build static qt instead of shared mod on linux so I downloaded qt 5.5.1 everywhere (source code) and I installed the stuff on this page on both ubuntu and fedora:


    I extracted the zip file and opened terminal in the folder and ran this:
    ./configure -platform linux-g++ -static -release

    the configuration was successful and It told me to run make so I ran make and these errors happened (this is on ubuntu but it was similar to this o fedora):

    g++ -Wl,-O1 -fuse-ld=gold -Wl,--enable-new-dtags -o chatserver .obj/main.o .obj/chatserver.o .obj/websocketclientwrapper.o .obj/websockettransport.o .obj/chatserver_plugin_import.o .obj/moc_chatserver.o .obj/moc_websocketclientwrapper.o .obj/moc_websockettransport.o -L/home/shahriar/Desktop/qt-everywhere-opensource-src-5.5.1/qtwebsockets/lib -lQt5WebSockets -L/home/shahriar/Desktop/qt-everywhere-opensource-src-5.5.1/qtbase/lib -L/home/shahriar/Desktop/qt-everywhere-opensource-src-5.5.1/qtwebchannel/lib -lQt5WebChannel -L/home/shahriar/Desktop/qt-everywhere-opensource-src-5.5.1/qtdeclarative/lib -lQt5Qml -L/home/shahriar/Desktop/qt-everywhere-opensource-src-5.5.1/qtbase/plugins/bearer -lqconnmanbearer -lqgenericbearer -lqnmbearer -lQt5Network -lQt5DBus -lQt5Core -lz -licui18n -licuuc -licudata -lpcre16 -lm -ldl -lgthread-2.0 -pthread -lglib-2.0 -lrt -lpthread
    /home/shahriar/Desktop/qt-everywhere-opensource-src-5.5.1/qtdeclarative/lib/libQt5Qml.a(qqmldebugserver.o):qqmldebugserver.cpp:function QQmlDebugServerThread::run(): error: undefined reference to 'QTcpServerConnection::QTcpServerConnection()'
    /home/shahriar/Desktop/qt-everywhere-opensource-src-5.5.1/qtdeclarative/lib/libQt5Qml.a(qqmldebugserver.o):qqmldebugserver.cpp:function QQmlDebugServerThread::run(): error: undefined reference to 'non-virtual thunk to QTcpServerConnection::setServer(QQmlDebugServer*)'
    collect2: error: ld returned 1 exit status
    Makefile:105: recipe for target 'chatserver' failed
    make[4]: *** [chatserver] Error 1
    make[4]: Leaving directory '/home/shahriar/Desktop/qt-everywhere-opensource-src-5.5.1/qtwebchannel/examples/webchannel/chatserver-cpp'
    Makefile:47: recipe for target 'sub-chatserver-cpp-make_first' failed
    make[3]: *** [sub-chatserver-cpp-make_first] Error 2
    make[3]: Leaving directory '/home/shahriar/Desktop/qt-everywhere-opensource-src-5.5.1/qtwebchannel/examples/webchannel'
    Makefile:42: recipe for target 'sub-webchannel-make_first' failed
    make[2]: *** [sub-webchannel-make_first] Error 2
    make[2]: Leaving directory '/home/shahriar/Desktop/qt-everywhere-opensource-src-5.5.1/qtwebchannel/examples'
    Makefile:69: recipe for target 'sub-examples-make_first' failed
    make[1]: *** [sub-examples-make_first] Error 2
    make[1]: Leaving directory '/home/shahriar/Desktop/qt-everywhere-opensource-src-5.5.1/qtwebchannel'
    Makefile:459: recipe for target 'module-qtwebchannel-make_first' failed
    make: *** [module-qtwebchannel-make_first] Error 2

    these are the last lines of make after waiting an hour. what sould I do to fix this problem?

  • Lifetime Qt Champion

    you can try with
    -nomake demos -nomake examples
    with ./configure (add to what u used)
    to skip the samples as it seems error in there.

  • Hi, you were right @mrjj
    I used this configuration and then used make:

    ./configure -static -developer-build -opensource -platform linux-g++ -opengl desktop -nomake examples -nomake tests

    and it didn't seem to have any errors.
    Now how do I use this to build my projects staticly?
    I know that there are two ways to do this. the first one is useing qmake from terminal and the second one is from qt IDE itself. the second way is easier so if anyone knows how to do this please tell me
    thanks in advance and thank you @mrjj

  • Lifetime Qt Champion


    Add that version of Qt to Qt Creator in the Build and Run panel and make a kit using it.

    On a side note, unless you plan to fix things / add features to Qt, you should drop the -developer-build option.

    Also, don't forget the licensing implication coming with a static build.

  • Hi, @SGaist thank you for helping
    alright so I did what you said and added the kit and built a very sipmple project in release mode but the size of the executable was 218 mb!!!

    so I built qt in static and release mode to see if the problem is because of the developer build. this is the config:

    ./configure -static -release -prefix /run/media/shahriar/Mine/Qt-release/qt-everywhere-opensource-src-5.5.1 -opensource -platform linux-g++ -opengl desktop -nomake examples -nomake tests

    the perfix path is the same as the source path

    these are the last lines of building in release with gmake:

    /run/media/shahriar/Mine/Qt-release/qt-everywhere-opensource-src-5.5.1/qtimageformats/plugins/imageformats/libqjp2.a(jas_stream.o):jas_stream.c:function jas_stream_tmpfile: warning: the use of tmpnam' is dangerous, better usemkstemp'
    gmake[3]: Leaving directory '/run/media/shahriar/Mine/Qt-release/qt-everywhere-opensource-src-5.5.1/qtquick1/tools/qmlplugindump'
    /run/media/shahriar/Mine/Qt-release/qt-everywhere-opensource-src-5.5.1/qtimageformats/plugins/imageformats/libqjp2.a(jas_stream.o):jas_stream.c:function jas_stream_tmpfile: warning: the use of tmpnam' is dangerous, better usemkstemp'
    gmake[3]: Leaving directory '/run/media/shahriar/Mine/Qt-release/qt-everywhere-opensource-src-5.5.1/qtquick1/tools/qml'
    gmake[2]: Leaving directory '/run/media/shahriar/Mine/Qt-release/qt-everywhere-opensource-src-5.5.1/qtquick1/tools'
    gmake[1]: Leaving directory '/run/media/shahriar/Mine/Qt-release/qt-everywhere-opensource-src-5.5.1/qtquick1'

    and I added the kit like you said and qt IDE gave me this warning:

    Non-installed -prefix build - for internal developement only

    what is this? is this OK?

  • Lifetime Qt Champion

    You have to call make install.

    And you shouldn't put the prefix in the sources, there's nothing to gain from that.

  • Hi @SGaist
    thank you it worked fine. on last thing:

    there is a warning under the kit in qt that says no qmlscene installed. will I have problem deploying quick applications?

  • Lifetime Qt Champion

    No, this is a helper tool that you can use to prototype QML application. You have more information about it here. You won't need it for deployment.

  • Hi and thank you all for helping. there only remains the licence issue. I think as long as I keep my apps open source there is no problem with releasing static apps

  • Lifetime Qt Champion

    As long as you abide by the GPL, you're good.

Log in to reply