- Building static Qt 5
- Contents
- Introdution
- Linux/Mac OS X
- Install dependencies
- Download sources
- Unpack archive
- Remove a glitchy JPEG2000 library (for Qt 5.5.1 and older)
- Configure
- Build and install
- Usage
- Windows
- Download and install dependencies
- Download sources
- Unpack archive
- Create a build script
- Build and install
- Qt Documentation
- Contents
- Step 1: Installing the License File (Commercially Licensed Qt Only)
- Step 2: Unpacking the Archive
- Step 3: Building the Library
- Step 4: Set the Environment Variables
- Step 5: Build the Qt Documentation
- Qt Documentation
- Contents
- Static Linking
- Building Qt Statically
- Linking the Application to the Static Version of Qt
- Shared Libraries
- Building Qt as a Shared Library
- Linking the Application to Qt as a Shared Library
- Creating the Application Package
- Application Dependencies
- Additional Libraries
Building static Qt 5
This is a detail guilde how to build the static version of the Qt framework. Static build of Qt allows you to build solid applications which will work without lots of additional *.DLL/*.SO or *.DYLIB files because everything will be hardcoded into your application.
Contents
Introdution
Static version of Qt allows you to build solid application files without packing of a lots of dependent libraries.
Don’t forget that with the static version of Qt, you can only legally release your GPL v3 licensed Open-Source applications! If you want to use the static Qt build in commercial development for closed-source applications, then you should buy the commercial license for that purpose.
Linux/Mac OS X
Install dependencies
Before start build you must install all necessary dependencies:
Install on Debian/Ubuntu/Mint
On Ubuntu 14.04 you also will need to install newer GCC compiler and CMake toolchain
Install on Mac OS X (before start you must have pre-installed latest version of XCode)
Download sources
At first, you must to download entire source code tarball from official Qt site:
Note: if this link is outdated, you can find newer version of Qt sources here:
Unpack archive
Unpack everything from the tarball into any folder (on Linux or on Mac OS X): tar -xvf qt-everywhere-opensource-src-5.8.0.tar.gz
Remove a glitchy JPEG2000 library (for Qt 5.5.1 and older)
For Qt 5.6 and higher this step must be skipped because JPEG2000 and MNG since Qt 5.6 are already disabled by default for security reasons.
This library provides a support of JPEG2000 image format support, but at the Moondust Project it’s useless (main image formats in the Moondust Project were PNG, GIF and BMP), and also causes a random crashes of Qt applications built with your Qt build.
To resolve next issues, recommended to remove building of JPE support:
because disabling of JPE building is not provided by ./configure script given with Qt sources, we must remove building of JPE weself:
- make a kill_jasper.sh file in parent folder of Qt sources folder
- on OS X: install via homebrew the coreutils and gnu-sed
- open a text editor (On OS X: Don’t use TextEditor.app, because it makes invalid code!, use text editor from XCode or use nano) and paste next content into it:
- open command line and execute this script by «bash ./kill_jasper.sh» command
Same for OSX with gnu-sed:
Configure
Open console then change current directory to new folder which you has been unpacked. then Copy-paste this into console ans press ENTER:
|
Linux Mint / Debian (for Qt 5.8 and higher)
|
macOS Sierra (for Qt 5.8 and higher)
|
Linux Mint / Debian (for Qt 5.7 and Qt 5.7.X)
Linux Mint / Debian (for Qt 5.6 and lower)
Mac OS X (for Qt 5.7 and Qt 5.7.X)
then wait while configuring will be finished (you will need to wait
Build and install
Hint: you can speed-up building process with adding -r argument, and adding -j x (where x — number of concurrent jobs. For example -j 4)
Final step is installation which will copy all built components into target installation directory
Usage
Built Qt will be located at
/Qt/5.5.1_static_osx on Mac OS X. To configure your Qt application to be built with static Qt version, you need to call
/Qt/5.5.1_static/bin/qmake while you in your project folder, and other steps are same as you build with regular Qt version.
If you wants to plug static build of Qt into Qt Creator, just make a new toolchain with your default compiler (GCC, CLang or MinGW on Windows systems) and debugger, and with your static build of Qt (find QMake in the bin subdirectory of your static Qt build)
Note: Carefully transfer packages with a static build of Qt, you should keep same absolute path (because it is hardcoded) if you don’t want to rebuild Qt again.
Windows
Download and install dependencies
Before start building you must download and install all dependencies:
- MinGW compiler taken through any way:
- Dynamic version of Qt (with included MinGW compiler)
- Separated installation of MinGW from official site
- MinGW-w64 installation
- 7-zip archivator (or any other which able to unpack 7z archives) to unpack source code
Download sources
To download latest version of source code just use this link (or find download link to latest version on official Qt site) Link to the latest version:
- http://download.qt.io/official_releases/qt/5.10/5.10.1/single/qt-everywhere-src-5.10.1.zip
Unpack archiveWhen you will download archive, open it and unpack into any convenient directory (but note: path must not contain non-ASCII characters [for example, Cyrillic, Chinese or Latin characters with diacritical signs, etc.]). Create a build scriptTo build Qt from sources need to make a right build script which will build static Qt.
Build script for Qt 5.8 and higher Build script for Qt 5.7 Make a «build_static_qt.bat» in any convenient directory and paste contents shown above. Then replace paths in the top paths to fit script into your actual environment, then save it. Build and installWhen you done everything, run your «build_static_qt.bat» script and wait 1.5 3 hours (dependent to your CPU power) until everything will be built. Источник Qt DocumentationContentsYou can download the Qt 5 sources from the Downloads page. For more information, visit the Getting Started with Qt page. Qt for X11 has some requirements that are given in more detail in the Qt for X11 Requirements document. Step 1: Installing the License File (Commercially Licensed Qt Only)If you use Qt with a commercial license, the Qt tools look for a local license file. If you are using a binary installer or the commercial Qt Creator, your licenses are automatically fetched and stored in your local user profile ( $XDG_DATA_HOME/Qt/qtlicenses.ini file). If you do not use any binary installer or Qt Creator, you can download the respective license file from your Qt Account Web portal and save it to your user profile as $HOME/.qt-license . If you prefer a different location or file name, you need to set the QT_LICENSE_FILE environment variable to the respective file path. Step 2: Unpacking the ArchiveUnpack the archive if you have not done so already. For example, if you have the qt-everywhere-opensource-src-%VERSION%.tar.gz package, type the following commands at a command line prompt: This creates the directory /tmp/qt-everywhere-opensource-src-%VERSION% containing the files from the archive. We only support the GNU version of the tar archiving utility. Note that on some systems it is called gtar. Step 3: Building the LibraryTo configure the Qt library for your machine type, run the ./configure script in the package directory. By default, Qt is configured for installation in the /usr/local/Qt-%VERSION% directory, but this can be changed by using the -prefix option. The Configure Options page contains more information about the configure options. To create the library and compile all the examples, tools, and tutorials, type: If -prefix is outside the build directory, you need to install the library, examples, tools, and tutorials in the appropriate place. To do this (as root if necessary), type: Note that on some systems the make utility is named differently, like gmake. The configure script tells you which make utility to use. Note: Later, if you need to reconfigure and rebuild Qt from the same location, ensure that all traces of the previous configuration are removed. To do so, from the build directory, type make confclean before running configure again. Step 4: Set the Environment VariablesTo use Qt, some environment variables need to be extended. This is done as follows: In .profile (if your shell is bash, ksh, zsh or sh), add the following lines: In .login (if your shell is csh or tcsh), add the following line: If you use a different shell, modify your environment variables accordingly. For compilers that do not support rpath you must also extend the LD_LIBRARY_PATH environment variable to include /usr/local/Qt-%VERSION%/lib . On Linux with GCC this step is not needed. Step 5: Build the Qt DocumentationFor the Qt reference documentation to be available in Qt Assistant, you must build it separately: В© 2021 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. Источник Qt DocumentationContentsThis documentation discusses specific deployment issues for Qt for Linux/X11. We will demonstrate the procedures in terms of deploying the Plug & Paint application that is provided in Qt’s examples directory. Due to the proliferation of Unix systems (such as commercial Unixes, Linux distributions, and so on), deployment on Unix is a complex topic. Before we start, be aware that programs compiled for one Unix flavor will probably not run on a different Unix system. For example, unless you use a cross-compiler, you cannot compile your application on Irix and distribute it on AIX. Static LinkingStatic linking is often the safest and easiest way to distribute an application on Unix since it relieves you from the task of distributing the Qt libraries and ensuring that they are located in the default search path for libraries on the target system. Building Qt StaticallyTo use this approach, you must start by installing a static version of the Qt library: We specify the prefix so that we do not overwrite the existing Qt installation. The example above only builds the Qt libraries, i.e. the examples and Qt Designer will not be built. When make is done, you will find the Qt libraries in the /path/to/Qt/lib directory. When linking your application against static Qt libraries, note that you might need to add more libraries to the LIBS line in your project file. For more information, see the Application Dependencies section. Linking the Application to the Static Version of QtOnce Qt is built statically, the next step is to regenerate the makefile and rebuild the application. First, we must go into the directory that contains the application: Now run qmake to create a new makefile for the application, and do a clean build to create the statically linked executable: You probably want to link against the release libraries, and you can specify this when invoking qmake . Note that we must set the path to the static Qt that we just built. To check that the application really links statically with Qt, run the ldd tool (available on most Unices): Verify that the Qt libraries are not mentioned in the output. Now, provided that everything compiled and linked without any errors, we should have a plugandpaint file that is ready for deployment. One easy way to check that the application really can be run stand-alone is to copy it to a machine that doesn’t have Qt or any Qt applications installed, and run it on that machine. Remember that if your application depends on compiler specific libraries, these must still be redistributed along with your application. For more information, see the Application Dependencies section. The Plug & Paint example consists of several components: The core application (Plug & Paint), and the Basic Tools and Extra Filters plugins. Since we cannot deploy plugins using the static linking approach, the executable we have prepared so far is incomplete. The application will run, but the functionality will be disabled due to the missing plugins. To deploy plugin-based applications we should use the shared library approach. Shared LibrariesWe have two challenges when deploying the Plug & Paint application using the shared libraries approach: The Qt runtime has to be correctly redistributed along with the application executable, and the plugins have to be installed in the correct location on the target system so that the application can find them. Building Qt as a Shared LibraryWe assume that you already have installed Qt as a shared library, which is the default when installing Qt, in the /path/to/Qt directory. Linking the Application to Qt as a Shared LibraryAfter ensuring that Qt is built as a shared library, we can build the Plug & Paint application. First, we must go into the directory that contains the application: Now run qmake to create a new makefile for the application, and do a clean build to create the dynamically linked executable: This builds the core application, the following will build the plugins: If everything compiled and linked without any errors, we will get a plugandpaint executable and the libpnp_basictools.so and libpnp_extrafilters.so plugin files. Creating the Application PackageThere is no standard package management on Unix, so the method we present below is a generic solution. See the documentation for your target system for information on how to create a package. To deploy the application, we must make sure that we copy the relevant Qt libraries (corresponding to the Qt modules used in the application), the platform plugin, and the executable to the same directory tree. Remember that if your application depends on compiler specific libraries, these must also be redistributed along with your application. For more information, see the Application Dependencies section. We’ll cover the plugins shortly, but the main issue with shared libraries is that you must ensure that the dynamic linker will find the Qt libraries. Unless told otherwise, the dynamic linker doesn’t search the directory where your application resides. There are many ways to solve this:
Note: If your application will be running with «Set user ID on execution,» and if it will be owned by root, then LD_LIBRARY_PATH will be ignored on some platforms. In this case, use of the LD_LIBRARY_PATH approach is not an option). The disadvantage of the first approach is that the user must have super user privileges. The disadvantage of the second approach is that the user may not have privileges to install into the predetermined path. In either case, the users don’t have the option of installing to their home directory. We recommend using the third approach since it is the most flexible. For example, a plugandpaint.sh script will look like this: By running this script instead of the executable, you are sure that the Qt libraries will be found by the dynamic linker. Note that you only have to rename the script to use it with other applications. When looking for plugins, the application searches in a plugins subdirectory inside the directory of the application executable. Either you have to manually copy the plugins into the plugins directory, or you can set the DESTDIR in the plugins’ project files: An archive distributing all the Qt libraries, and all the plugins, required to run the Plug & Paint application, would have to include the following files:
On most systems, the extension for shared libraries is .so . A notable exception is HP-UX, which uses .sl . Remember that if your application depends on compiler specific libraries, these must still be redistributed along with your application. For more information, see the Application Dependencies section. To verify that the application now can be successfully deployed, you can extract this archive on a machine without Qt and without any compiler installed, and try to run it, i.e. run the plugandpaint.sh script. An alternative to putting the plugins in the plugins subdirectory is to add a custom search path when you start your application using QApplication::addLibraryPath() or QApplication::setLibraryPaths(). Application DependenciesAdditional LibrariesTo find out which libraries your application depends on, run the ldd tool (available on most Unices): This will list all the shared library dependencies for your application. Depending on configuration, these libraries must be redistributed along with your application. In particular, the standard C++ library must be redistributed if you’re compiling your application with a compiler that is binary incompatible with the system compiler. When possible, the safest solution is to link against these libraries statically. You will probably want to link dynamically with the regular X11 libraries, since some implementations will try to open other shared libraries with dlopen() , and if this fails, the X11 library might cause your application to crash. It’s also worth mentioning that Qt will look for certain X11 extensions, such as Xinerama and Xrandr, and possibly pull them in, including all the libraries that they link against. If you can’t guarantee the presence of a certain extension, the safest approach is to disable it when configuring Qt (e.g. ./configure -no-xrandr ). FontConfig and FreeType are other examples of libraries that aren’t always available or that aren’t always binary compatible. As strange as it may sound, some software vendors have had success by compiling their software on very old machines and have been very careful not to upgrade any of the software running on them. When linking your application against the static Qt libraries, you must explicitly link with the dependent libraries mentioned above. Do this by adding them to the LIBS variable in your project file. From Qt version 5.2 onwards, the officially supported version for OpenSSL is 1.0.0 or later. Versions >= 0.9.7 and libqxcb.so . This file must be located within a specific subdirectory (by default, platforms ) under your distribution directory. Alternatively, it is possible to adjust the search path Qt uses to find its plugins, as described below. Your application may also depend on one or more Qt plugins, such as the JPEG image format plugin or a SQL driver plugin. Be sure to distribute any Qt plugins that you need with your application. Similar to the platform plugin, each type of plugin must be located within a specific subdirectory (such as imageformats or sqldrivers ) within your distribution directory. The search path for Qt plugins (as well as a few other paths) is hard-coded into the QtCore library. By default, the first plugin search path will be hard-coded as /path/to/Qt/plugins . As mentioned above, using predetermined paths has certain disadvantages, so you need to examine various alternatives to make sure that the Qt plugins are found:
The How to Create Qt Plugins document outlines the issues you need to pay attention to when building and deploying plugins for Qt applications. В© 2021 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners. Источник |