C++ 如何在Windows或Linux、32位或64位、Visual Studio或g+上静态或动态编译Qt 5+;
因为我没有博客,所以只是一篇帮助那些想这么做的人的帖子C++ 如何在Windows或Linux、32位或64位、Visual Studio或g+上静态或动态编译Qt 5+;,c++,visual-studio-2010,qt,compilation,visual-studio-2012,C++,Visual Studio 2010,Qt,Compilation,Visual Studio 2012,因为我没有博客,所以只是一篇帮助那些想这么做的人的帖子 这也适用于linux。请随意编辑和改进。注意:我在Windows上还写了另一篇文章。您可以为Linux修改它,因为区别在本文中显示 这篇文章正在不断更新。如果这对你有帮助,请竖起大拇指,让我知道这是在帮助别人,而不是毫无用处 如果您有任何意见或发现拼写错误,请让我知道,以便我可以修复它们 首先,编译32位还是64位版本并不重要。唯一的区别是必须从VisualStudio中选择命令提示符快捷方式,它将初始化不同的环境变量 让我们从这个开始:
这也适用于linux。请随意编辑和改进。注意:我在Windows上还写了另一篇文章。您可以为Linux修改它,因为区别在本文中显示 这篇文章正在不断更新。如果这对你有帮助,请竖起大拇指,让我知道这是在帮助别人,而不是毫无用处 如果您有任何意见或发现拼写错误,请让我知道,以便我可以修复它们 首先,编译32位还是64位版本并不重要。唯一的区别是必须从VisualStudio中选择命令提示符快捷方式,它将初始化不同的环境变量
让我们从这个开始:
C:\Qt\Qt5.6
,现在可以在C:\Qt\Qt5.6\qtbase
中找到文件夹qtbase
- a对于VS2012:qtbase\mkspecs\win32-msvc2012\qmake.conf
- b对于VS2010:qtbase\mkspecs\win32-msvc2010\qmake.conf
- c适用于Qt 5.5.0及更高版本(任何VS版本):qtbase\mkspecs\common\msvc-desktop.conf
QMAKE_CFLAGS_RELEASE = -O2 -MD
QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi
QMAKE_CFLAGS_DEBUG = -Zi -MDd
到
-static runtime
,可以为您完成此操作。对于新版本的Qt,您可能不再需要手动执行此操作
- 对于VS2012:对于VS2012执行以下命令
set QMAKESPEC=win32-msvc2012 set QTDIR=C:\Qt\Qt5.7\qtbase set PATH=C:\Qt\Qt5.7\qtbase\bin;%PATH%
QMAKESPEC
环境变量被认为是错误的。不要在新版本中这样做
用于动态链接(需要8 GBs)
用于无示例的动态链接(需要2 GB)
对于静态链接(需要70 GB,是的,这太疯狂了,不制作示例和演示更合理)
对于没有示例的静态链接(需要4 GB,更有意义)
现在需要一两分钟,然后按如下方式使用jom(假设它是在C:\Qt\jom中提取的):
50表示要使用的核心数。我使用50,因为我有8个线程,仅使用8个线程不会完全占用所有内核,所以更多的线程更好,但不要太贪心,因为这可能会使系统没有响应能力
- 对于VS2010:对于VS2010执行以下命令
set QMAKESPEC=win32-msvc2010 set QTDIR=C:\Qt\Qt5.7\qtbase set PATH=C:\Qt\Qt5.7\qtbase\bin;%PATH%
QMAKESPEC
环境变量被认为是错误的。不要在新版本中这样做。
用于动态链接(需要8 GBs)
用于无示例的动态链接(需要2 GB)
最后一个命令取决于要编译的内容。只需键入configure-help并查看可用的命令行参数。
对于静态链接(需要70 GB,是的,这太疯狂了,不制作示例和演示更合理)
对于没有示例的静态链接(需要4 GB,更有意义)
现在需要一两分钟,然后按如下方式使用jom(假设它是在C:\Qt\jom中提取的):
50表示要使用的核心数。我使用50,因为我有8个线程,仅使用8个线程不会完全占用所有内核,所以更多的线程更好,但不要太贪心,因为这可能会使系统没有响应能力
- 对于linux:
export QMAKESPEC=linux-g++
export QTDIR=/home/username/Qt5.7/qtbase
export PATH=/home/username/Qt5.7/qtbase/bin:$PATH
注意:对于Qt版本5.8+,设置QMAKESPEC
环境变量被认为是错误的。不要在新版本中这样做
假设您想安装t
configure -debug-and-release -opensource -platform win32-msvc2012 -opengl desktop -nomake examples -nomake tests
Now the last command depends on what you want to compile. Just type configure -help and see what the available command-line parameters are.
configure -debug-and-release -opensource -platform win32-msvc2012 -opengl desktop -static
configure -debug-and-release -opensource -platform win32-msvc2012 -opengl desktop -static -nomake examples -nomake tests
C:\Qt\jom\jom.exe -j 50
set QMAKESPEC=win32-msvc2010
set QTDIR=C:\Qt\Qt5.7\qtbase
set PATH=C:\Qt\Qt5.7\qtbase\bin;%PATH%
configure -debug-and-release -opensource -platform win32-msvc2010 -opengl desktop
configure -debug-and-release -opensource -platform win32-msvc2010 -opengl desktop -nomake examples -nomake tests
configure -debug-and-release -opensource -platform win32-msvc2010 -opengl desktop -static
configure -debug-and-release -opensource -platform win32-msvc2010 -opengl desktop -static -nomake examples -nomake tests
C:\Qt\jom\jom.exe -j 50
export QMAKESPEC=linux-g++
export QTDIR=/home/username/Qt5.7/qtbase
export PATH=/home/username/Qt5.7/qtbase/bin:$PATH
-prefix /home/username/Qt5.7-install
./configure -debug-and-release -opensource -platform linux-g++ -opengl desktop
./configure -debug-and-release -opensource -platform linux-g++ -opengl desktop -nomake examples -nomake tests
./configure -debug-and-release -opensource -platform linux-g++ -opengl desktop -static
./configure -debug-and-release -opensource -platform linux-g++ -opengl desktop -static -nomake examples -nomake tests
make -j 50