問題描述
只是為了幫助那些試圖這樣做的人的帖子,因為我沒有博客.
這也適用于 linux.隨意編輯和改進它.
注意:我還寫了另一篇文章給
9.
對于VS2012:針對VS2012執行以下命令
設置 QMAKESPEC=win32-msvc2012設置 QTDIR=C:QtQt5.7qtbase設置 PATH=C:QtQt5.7qtbasein;%PATH%
注意:對于 Qt 5.8+ 版本,設置 QMAKESPEC
環境變量被認為是錯誤的.不要為新版本這樣做.
用于動態鏈接(需要 8 GB)
configure -debug-and-release -opensource -platform win32-msvc2012 -opengl desktop
用于沒有示例的動態鏈接(需要 2 GB)
configure -debug-and-release -opensource -platform win32-msvc2012 -opengl desktop -nomake examples -nomake tests現在最后一個命令取決于您要編譯的內容.只需鍵入 configure -help 并查看可用的命令行參數是什么.
對于靜態鏈接(需要 70 GB,是的,這很瘋狂,不制作示例和演示更合理).
configure -debug-and-release -opensource -platform win32-msvc2012 -opengl desktop -static
對于沒有示例的靜態鏈接(需要 4 GB,更有意義).
configure -debug-and-release -opensource -platform win32-msvc2012 -opengl desktop -static -nomake examples -nomake tests
現在這將需要一兩分鐘,然后按如下方式使用 jom(假設它是在 C:Qtjom 中提取的):
C:Qtjomjom.exe -j 50
50 表示您要使用的內核數.我使用 50 是因為我有 8 個線程,并且只使用 8 個不會完全占用所有內核,所以更多更好,但不要太貪婪,因為它可能會使您的系統沒有響應.
對于VS2010:對于VS2010執行以下命令
set QMAKESPEC=win32-msvc2010設置 QTDIR=C:QtQt5.7qtbase設置 PATH=C:QtQt5.7qtbasein;%PATH%
注意:對于 Qt 5.8+ 版本,設置 QMAKESPEC
環境變量被認為是錯誤的.不要為新版本這樣做.用于動態鏈接(需要 8 GB)
configure -debug-and-release -opensource -platform win32-msvc2010 -opengl desktop
用于沒有示例的動態鏈接(需要 2 GB)
configure -debug-and-release -opensource -platform win32-msvc2010 -opengl desktop -nomake examples -nomake tests
最后一條命令取決于您要編譯的內容.只需鍵入 configure -help 并查看可用的命令行參數是什么.對于靜態鏈接(需要 70 GB,是的,這很瘋狂,不制作示例和演示更合理).
configure -debug-and-release -opensource -platform win32-msvc2010 -opengl desktop -static
對于沒有示例的靜態鏈接(需要 4 GB,更有意義).
configure -debug-and-release -opensource -platform win32-msvc2010 -opengl desktop -static -nomake examples -nomake tests
現在這將需要一兩分鐘,然后按如下方式使用 jom(假設它是在 C:Qtjom 中提取的):
C:Qtjomjom.exe -j 50
50 表示您要使用的內核數.我使用 50 是因為我有 8 個線程,并且只使用 8 個不會完全占用所有內核,所以更多更好,但不要太貪婪,因為它可能會使您的系統沒有響應.
- 對于 linux:
Linux 與 Windows 有一個小區別.建議在linux下編譯后安裝.老實說,這是對我來說沒有問題的唯一方法.
Linux 執行以下命令.不要忘記用 Qt 源的正確路徑替換路徑
export QMAKSPEC=linux-g++導出 QTDIR=/home/username/Qt5.7/qtbase導出路徑=/home/username/Qt5.7/qtbase/bin:$PATH
注意:對于 Qt 5.8+ 版本,設置 QMAKESPEC
環境變量被認為是錯誤的.不要為新版本這樣做.
假設您要將編譯后的源代碼安裝到目錄/home/username/Qt5.7-install
.在這種情況下,將以下內容添加到以下 any 配置命令中:
-prefix/home/username/Qt5.7-install
警告:請勿安裝到同一源目錄.這完全是錯誤的!
如果沒有設置-prefix
,會選擇默認路徑,我猜是/usr/local/
.我不喜歡使用 root 安裝任何東西.我總是更喜歡在我的用戶文件夾中安裝,這樣可逆性和升級都不是問題.
以下是不同的 configure
命令,具體取決于您要執行的操作.
用于動態鏈接(需要 8 GB)
./configure -debug-and-release -opensource -platform linux-g++ -opengl desktop
用于沒有示例的動態鏈接(需要 2 GB)
./configure -debug-and-release -opensource -platform linux-g++ -opengl desktop -nomake examples -nomake tests
現在最后一個命令取決于您要編譯的內容.只需輸入 ./configure -help
并查看可用的命令行參數.
對于靜態鏈接(需要 70 GB,是的,這很瘋狂,不做示例和測試更合理).
./configure -debug-and-release -opensource -platform linux-g++ -opengl desktop -static
對于沒有示例的靜態鏈接(需要 4 GB,更有意義).
./configure -debug-and-release -opensource -platform linux-g++ -opengl desktop -static -nomake examples -nomake tests
制作完成后,運行make命令
make -j 50
50 表示您要使用的內核數.我使用 50 是因為我有 8 個線程,并且只使用 8 個不會完全占用所有內核,所以更多更好,但不要太貪婪,因為它可能會使您的系統沒有響應.
等待 2 個多小時直到編譯完成.
清理!在 Windows 上使用此命令可以節省大量空間:
C:Qtjomjom.exe clean
而對于 linux 使用此命令:make clean
您可以將編譯文件夾的大小從 8 GB 減少到 2.5 GB(用于動態鏈接),從 70 GB 減少到 35 GB(用于靜態鏈接).
<小時>為了在 Qt Creator 中使用這個編譯版本:
- 啟動 Qt Creator
- 轉到工具、選項
- 從左側的列表中選擇構建并運行".
- 轉到Qt 版本"標簽
單擊添加"并從 bin 所在的文件夾中選擇 qmakeqtbase 是,所以從上面:
C:QtQt5.7qtbaseinqmake.exe
(或者Linux選擇你安裝編譯好的Qt源碼的路徑,相當于本教程中的/home/username/Qt5.7-install/qtbase/bin/qmake
)
- 點擊應用"
- 轉到套件"標簽
- 點擊添加"
- 給它一個名字,選擇合適的編譯器(對于 VISUAL STUDIOEXPRESS DO NOT SELECT amd64 FOR 64-BIT ,它行不通,選擇x86_amd64 代替)
- 點擊確定.
現在只需打開一個項目,您就會發現它要求您選擇添加的工具包.
享受:)
Just a post to help those guys trying to do that, since I don't have a blog.
This works for linux too. Feel free to edit it and improve it.
Note: There's also another article I wrote to compile from GIT source here with an automated script on Windows. You may modify it for Linux as the difference is shown in this post.
This article is continuously being updated. If this helps you, please give it a "thumbs up" so that I could know that it's helping people and not being useless.
If you have any comments or you found typos, please let me know so that I can fix them.
First thing, it doesn't matter whether you want to compile 32 or 64 bit version. The only difference is the command prompt shortcut that you have to choose from Visual Studio, which will initialize different environment variables.
Let's begin with this:
Download and install Perl: Download link
Download and install Python: Download link
Download and install Windows SDK (probably not necessary, but recommended) I use Windows 8, so this is the version I used: Download link ,Otherwise find the proper version for your Windows.
Download and install DirectX SDK (probably necessary if you wanna compile with OpenGL) Download link
Download and extract jom to some folder (not needed for linux) (jom is a tool for compiling stuff with VS in parallel, there's a way to do this with nmake, but I'm not familiar with it) Download link
Download Qt Opensource, and extract it, say to
C:QtQt5.6
, so now the folderqtbase
can be found inC:QtQt5.6qtbase
.Only for Windows: DO YOU REALLY WANT IT TOTALLY STATIC?
Usually, even if you choose the compilation to be static, the compiler itself will still not merge its libraries statically. If you want your compiled source to be fully static with respect to the compiler (Visual Studio), you have to do this tweak in the QMAKE files of Qt.
Go to the file (starting from your Qt source directory), for versions higher than 2012, just use the right version everywhere (such as win32-msvc2015):
a. For VS2012: qtbasemkspecswin32-msvc2012qmake.conf
b. For VS2010: qtbasemkspecswin32-msvc2010qmake.conf
c. For Qt 5.5.0 and later (with any VS version): qtbasemkspecscommonmsvc-desktop.conf
and edit the following lines
QMAKE_CFLAGS_RELEASE = -O2 -MD QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MD -Zi QMAKE_CFLAGS_DEBUG = -Zi -MDd
to
QMAKE_CFLAGS_RELEASE = -O2 -MT QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO += -O2 -MT -Zi QMAKE_CFLAGS_DEBUG = -Zi -MTd
Note: Qt 5.6+ have a configure parameter -static-runtime
that will do this for you. You may not need to do this manually anymore for new versions of Qt.
Start the terminal in linux, or in Windows, start the terminals of Visual Studio (which have the correct environment variables set, or alternatively use vcvarsall.bat). To start the command prompt and let it do this automatically for you, go to Start, All Programs:
For Windows versions prior to 8: Find the Microsoft Visual Studio 201x folder, and launch the command prompt (either x86 for 32 bit or x64 for 64 bit).
For Windows 8: go to Start, type "cmd" and all versions available for command prompt will show up. Choose the Visual Studio version appropriate (x86 for 32 bit or x64 for 64 bit).
Following is a screenshot of how it may look like. Always tend to select "Native" if it exists.
9.
For VS2012: Execute the following commands for VS2012
set QMAKESPEC=win32-msvc2012 set QTDIR=C:QtQt5.7qtbase set PATH=C:QtQt5.7qtbasein;%PATH%
Note: Setting QMAKESPEC
environment variable is considered wrong for Qt versions 5.8+. Don't do it for the new versions.
For dynamic linking (needs 8 GBs)
configure -debug-and-release -opensource -platform win32-msvc2012 -opengl desktop
For dynamic linking with no examples (needs 2 GB)
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.
For static linking (needs 70 GBs, yes it's crazy, it's more reasonable not to make the examples and demos).
configure -debug-and-release -opensource -platform win32-msvc2012 -opengl desktop -static
For static linking with no examples (needs 4 GBs, makes more sense).
configure -debug-and-release -opensource -platform win32-msvc2012 -opengl desktop -static -nomake examples -nomake tests
Now this will take a minute or two, then use jom as follows (assuming it's extracted in C:Qtjom):
C:Qtjomjom.exe -j 50
50 represents the number of cores you want to use. I use 50 because I have 8 threads and using only 8 will not occupy all cores completely, so more is better, but don't get too greedy as it could make your system not responsive.
For VS2010: Execute the following commands for VS2010
set QMAKESPEC=win32-msvc2010 set QTDIR=C:QtQt5.7qtbase set PATH=C:QtQt5.7qtbasein;%PATH%
Note: Setting QMAKESPEC
environment variable is considered wrong for Qt versions 5.8+. Don't do it for the new versions.
For dynamic linking (needs 8 GBs)
configure -debug-and-release -opensource -platform win32-msvc2010 -opengl desktop
For dynamic linking with no examples (needs 2 GB)
configure -debug-and-release -opensource -platform win32-msvc2010 -opengl desktop -nomake examples -nomake tests
The last command depends on what you want to compile. Just type configure -help and see what the available command-line parameters are. For static linking (needs 70 GBs, yes it's crazy, it's more reasonable not to make the examples and demos).
configure -debug-and-release -opensource -platform win32-msvc2010 -opengl desktop -static
For static linking with no examples (needs 4 GBs, makes more sense).
configure -debug-and-release -opensource -platform win32-msvc2010 -opengl desktop -static -nomake examples -nomake tests
Now this will take a minute or two, then use jom as follows (assuming it's extracted in C:Qtjom):
C:Qtjomjom.exe -j 50
50 represents the number of cores you want to use. I use 50 because I have 8 threads and using only 8 will not occupy all cores completely, so more is better, but don't get too greedy as it could make your system not responsive.
- For linux:
There's one small difference for Linux over Windows. It's recommended in linux to install after compiling. Honestly this is the only way it works for me without problems.
Execute the following commands for Linux. Don't forget to replace the paths with the correct paths of your Qt source
export QMAKESPEC=linux-g++
export QTDIR=/home/username/Qt5.7/qtbase
export PATH=/home/username/Qt5.7/qtbase/bin:$PATH
Note: Setting QMAKESPEC
environment variable is considered wrong for Qt versions 5.8+. Don't do it for the new versions.
Let's say you want to install the compiled source to the directory /home/username/Qt5.7-install
. In this case, add the following to any of the configure commands below:
-prefix /home/username/Qt5.7-install
Warning: DO NOT install to the same source directory. That's plain wrong!
If -prefix
is not set, the default path will be chosen, which is /usr/local/
I guess. I don't like to install anything using root. I always prefer installing in my user folder, so that reversibility and upgrades are not a problem.
The following are different possible configure
commands depending on what you want to do.
For dynamic linking (needs 8 GBs)
./configure -debug-and-release -opensource -platform linux-g++ -opengl desktop
For dynamic linking with no examples (needs 2 GB)
./configure -debug-and-release -opensource -platform linux-g++ -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.
For static linking (needs 70 GBs, yes it's crazy, it's more reasonable not to make the examples and tests).
./configure -debug-and-release -opensource -platform linux-g++ -opengl desktop -static
For static linking with no examples (needs 4 GBs, makes more sense).
./configure -debug-and-release -opensource -platform linux-g++ -opengl desktop -static -nomake examples -nomake tests
After making is done, run make command
make -j 50
50 represents the number of cores you want to use. I use 50 because I have 8 threads and using only 8 will not occupy all cores completely, so more is better, but don't get too greedy as it could make your system not responsive.
Wait 2+ hours till the compilation is complete.
Clean up! You can save a lot of space using this command for Windows:
C:Qtjomjom.exe clean
And this command for linux:make clean
You can reduce the size of your compiled folder from 8 GB to 2.5 GB (for dynamic linking) and from 70 GB to 35 GB (for static linking).
In order to use this compiled version in Qt Creator:
- Start Qt Creator
- Go to Tools, Options
- Select Build and Run from the list on the left.
- Go to "Qt Versions" tab
Click on "Add" and select qmake from the folder where your bin in qtbase is, so from above:
C:QtQt5.7qtbaseinqmake.exe
(or for Linux choose the path where you installed the compiled Qt source, which is equivalent to /home/username/Qt5.7-install/qtbase/bin/qmake
in this tutorial)
- Click "Apply"
- Go to "Kits" tab
- Click "Add"
- Give it a name, choose the appropriate compiler (FOR VISUAL STUDIO EXPRESS DO NOT SELECT amd64 FOR 64-BIT , IT WON'T WORK, CHOOSE x86_amd64 INSTEAD)
- Click OK.
Now just open a project and you'll find it asking you to choose the kit you added.
Enjoy :)
這篇關于如何在 Windows 或 Linux,32 或 64 位,在 Visual Studio 或 g++ 上靜態或動態編譯 Qt 5的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!