Qt for macOS - 从源代码构建

Qt for macOS has some requirements that are given in more detail in the Qt for macOS Requirements 文档。

The following instructions describe how to install Qt from the source package. You can download the Qt 5 sources from the 下载 页面。更多信息,拜访 Qt 快速入门 页面。

步骤 1:安装许可文件 (仅商业许可的 Qt)

若在商业许可下使用 Qt,则 Qt 工具会查找本地许可文件。若正使用二进制安装程序或商用 Qt Creator,则会自动取出许可并存储在本地用户 Profile (配置文件) 中 ( $HOME/Library/Application Support/Qt/qtlicenses.ini file).

若不使用任何二进制安装程序或 Qt Creator,可以下载各自的许可文件从您的 Qt 帐户 Web 门户并将其保存到您的用户 Profile (配置文件) 作为 $HOME/.qt-license 。若偏爱不同的位置或文件名,需要设置 QT_LICENSE_FILE 环境变量到各个文件路径。

步骤 2:解包存档

Unpack 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:

cd /tmp
gunzip qt-everywhere-opensource-src-%VERSION%.tar.gz        # uncompress the archive
tar xvf qt-everywhere-opensource-src-%VERSION%.tar          # unpack it
					

This creates the directory /tmp/qt-everywhere-opensource-src-%VERSION% containing the files from the archive.

Step 3: Build the Qt Library

To 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 选项。

cd /tmp/qt-everywhere-opensource-src-%VERSION%
./configure
					

By default, Qt is built as a framework, but you can built it as a set of dynamic libraries (dylibs) by specifying the -no-framework 选项。

Qt can also be configured to be built with debugging symbols. This process is described in detail in the 调试技术 文档。

The 配置选项 页面包含有关 configure 选项的更多信息。

To create the library and compile all the examples and tools, type:

make
					

-prefix is outside the build directory, you need to install the library, examples, and tools in the appropriate place. To do this, type:

sudo make -j1 install
					

This command requires that you have administrator access on your machine.

注意: There is a potential race condition when running make install with multiple jobs. It is best to only run one make job (-j1) for the install.

Step 4: Set the Environment Variables

In order to use Qt, some environment variables need to be extended.

PATH               - to locate qmake, moc and other Qt tools
					

This is done like this:

.profile (if your shell is bash), add the following lines:

PATH=/usr/local/Qt-%VERSION%/bin:$PATH
export PATH
					

.login (in case your shell is csh or tcsh), add the following line:

setenv PATH /usr/local/Qt-%VERSION%/bin:$PATH
					

If you use a different shell, please modify your environment variables accordingly.

That's all. Qt is now installed.