Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Statlic linking of Qt and C++ libraries
I'm writing a program using Qt and libstd++. target machine probably does not have any of them installed. I would like to statically link all Qt and other c++ libraries used in my application. Adding CONFIG += static into the .pro file didn't help.
You have to build Qt itself as a static library. Check out the help for the configure script of Qt fo rmore info but you will at least need to use the -static option when configuring Qt.
I have installed Qt from Ubuntu repository. Could you tell me please how do I statically re-compile Qt? I have to install Qt development files?
Yes download the qt-everywhere source tarball from "here":http://qt.nokia.com/downloads/linux-x11-cpp. Then extract it somewhere, configure it with something like:
@./configure -static -prefix $HOME/development/qt-static-4.7.2@
Then make and make install as per usual.
Once that is done, simply use the version of qmake that gets installed rather than the system-supplied qmake. You can do this by editing your $PATH environment variable to pick up your new qmake first or you could set up and alias or just use the full path to it.
Ok, I'm going to download and compile.
Ok, I'm unable to compile Qt ! my download failed last day (when I moved my notebook from university to home :-( and I have to redownload it.
Currently I have installed qt-sdk 64-bit version from repositories. Is there a way to link shared libraries like as static libraries? I also have to compile a 32-bit program :-) I'm looking for a way to avoid download and compile...
I thought that the sdk shipped the sources along with it? Just build those if you already have them to hand. You can rebuild and install in as many configurations as you like. The same source tree applies to all.
There are header files in /usr/include/qt4 directory. But there are no any configuration or make or even source codes. I don't know if they are correct sources or not, or if I will be able to revert them to previous state or not. think there are just headers and compiled libraries included in packages.
I'm going to download the source code.
Thanks you :-)
giesbert last edited by
If you download the SDK beta (and I think also RC) the structure is changed :-)
You have the headers without links, no sources inside. You can also download / install the sourc4s with the installer, but it is different from the pure source package where the include files from include point to the sources dir.
To rebuild Qt, you now have to download the real source zip or tar file.
bq. ./configure -static -prefix $HOME/development/qt-static-4.7.2
I tested my program in target machine. It works!
Thanks in advance :-)
Congratulations! Good luck with the rest of your project.