pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

如何在 Windows 或 Linux,32 或 64 位,在 Visual Stud

How to compile Qt 5 under Windows or Linux, 32 or 64 bit, static or dynamic on Visual Studio or g++(如何在 Windows 或 Linux,32 或 64 位,在 Visual Studio 或 g++ 上靜態或動態編譯 Qt 5) - IT屋-程序員軟件開發技術分享
本文介紹了如何在 Windows 或 Linux,32 或 64 位,在 Visual Studio 或 g++ 上靜態或動態編譯 Qt 5的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

只是為了幫助那些試圖這樣做的人的帖子,因為我沒有博客.

這也適用于 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 個不會完全占用所有內核,所以更多更好,但不要太貪婪,因為它可能會使您的系統沒有響應.

  1. 等待 2 個多小時直到編譯完成.

  2. 清理!在 Windows 上使用此命令可以節省大量空間:C:Qtjomjom.exe clean 而對于 linux 使用此命令:make clean

您可以將編譯文件夾的大小從 8 GB 減少到 2.5 GB(用于動態鏈接),從 70 GB 減少到 35 GB(用于靜態鏈接).

<小時>

為了在 Qt Creator 中使用這個編譯版本:

  1. 啟動 Qt Creator
  2. 轉到工具、選項
  3. 從左側的列表中選擇構建并運行".
  4. 轉到Qt 版本"標簽
  5. 單擊添加"并從 bin 所在的文件夾中選擇 qmakeqtbase 是,所以從上面:

    C:QtQt5.7qtbaseinqmake.exe

(或者Linux選擇你安裝編譯好的Qt源碼的路徑,相當于本教程中的/home/username/Qt5.7-install/qtbase/bin/qmake)

  1. 點擊應用"
  2. 轉到套件"標簽
  3. 點擊添加"
  4. 給它一個名字,選擇合適的編譯器(對于 VISUAL STUDIOEXPRESS DO NOT SELECT amd64 FOR 64-BIT ,它行不通,選擇x86_amd64 代替)
  5. 點擊確定.

現在只需打開一個項目,您就會發現它要求您選擇添加的工具包.

享受:)

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:

  1. Download and install Perl: Download link

  2. Download and install Python: Download link

  3. 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.

  4. Download and install DirectX SDK (probably necessary if you wanna compile with OpenGL) Download link

  5. 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

  6. Download Qt Opensource, and extract it, say to C:QtQt5.6, so now the folder qtbase can be found in C:QtQt5.6qtbase .

  7. 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.

  1. 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.

  1. Wait 2+ hours till the compilation is complete.

  2. 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:

  1. Start Qt Creator
  2. Go to Tools, Options
  3. Select Build and Run from the list on the left.
  4. Go to "Qt Versions" tab
  5. 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)

  1. Click "Apply"
  2. Go to "Kits" tab
  3. Click "Add"
  4. 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)
  5. 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模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數據?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環: for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環?)
Reusing thread in loop c++(在循環 C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環形?)
主站蜘蛛池模板: 四川成都干燥设备_回转筒干燥机_脉冲除尘器_输送设备_热风炉_成都川工星科机电设备有限公司 | 数码听觉统合训练系统-儿童感觉-早期言语评估与训练系统-北京鑫泰盛世科技发展有限公司 | 杭州门窗厂家_阳光房_包阳台安装电话-杭州窗猫铝合金门窗 | 华溶溶出仪-Memmert稳定箱-上海协烁仪器科技有限公司 | 卡诺亚轻高定官网_卧室系统_整家定制_定制家居_高端定制_全屋定制加盟_定制家具加盟_定制衣柜加盟 | 电渗析,废酸回收,双极膜-山东天维膜技术有限公司 | QQ房产导航-免费收录优秀房地产网站_房地产信息网 | 工程管道/塑料管材/pvc排水管/ppr给水管/pe双壁波纹管等品牌管材批发厂家-河南洁尔康建材 | 筒瓦厂家-仿古瓦-寺庙-古建琉璃瓦-宜兴市古典园林建筑陶瓷厂有限公司 | 铝镁锰板厂家_进口钛锌板_铝镁锰波浪板_铝镁锰墙面板_铝镁锰屋面-杭州军晟金属建筑材料 | 南京和瑞包装有限公司| 食品质构分析仪-氧化诱导分析仪-瞬态法导热系数仪|热冰百科 | 郑州宣传片拍摄-TVC广告片拍摄-微电影短视频制作-河南优柿文化传媒有限公司 | 硬度计,金相磨抛机_厂家-莱州华煜众信试验仪器有限公司 | 土壤养分检测仪|土壤水分|土壤紧实度测定仪|土壤墒情监测系统-土壤仪器网 | 熔体泵|换网器|熔体齿轮泵|熔体计量泵厂家-郑州巴特熔体泵有限公司 | 带式压滤机_污泥压滤机_污泥脱水机_带式过滤机_带式压滤机厂家-河南恒磊环保设备有限公司 | UV-1800紫外光度计-紫外可见光度计厂家-翱艺仪器(上海)有限公司 | 亚洲工业智能制造领域专业门户网站 - 亚洲自动化与机器人网 | 高速混合机_锂电混合机_VC高效混合机-无锡鑫海干燥粉体设备有限公司 | 注塑模具_塑料模具_塑胶模具_范仕达【官网】_东莞模具设计与制造加工厂家 | 首页-浙江橙树网络技术有限公司 石磨面粉机|石磨面粉机械|石磨面粉机组|石磨面粉成套设备-河南成立粮油机械有限公司 | 吹田功率计-长创耐压测试仪-深圳市新朗普电子科技有限公司 | [品牌官网]贵州遵义双宁口腔连锁_贵州遵义牙科医院哪家好_种植牙_牙齿矫正_原华美口腔 | 高速龙门架厂家_监控杆_多功能灯杆_信号灯杆_锂电池太阳能路灯-鑫世源照明 | 双舌接地线-PC68数字式高阻计-ZC36|苏海百科 | 二手色谱仪器,十万分之一分析天平,蒸发光检测器,电位滴定仪-湖北捷岛科学仪器有限公司 | 风电变桨伺服驱动器-风电偏航变桨系统-深圳众城卓越科技有限公司 | 沈阳楼承板_彩钢板_压型钢板厂家-辽宁中盛绿建钢品股份有限公司 轴承振动测量仪电箱-轴承测振动仪器-测试仪厂家-杭州居易电气 | 不锈钢轴流风机,不锈钢电机-许昌光维防爆电机有限公司(原许昌光维特种电机技术有限公司) | 深圳富泰鑫五金_五金冲压件加工_五金配件加工_精密零件加工厂 | 心肺复苏模拟人|医学模型|急救护理模型|医学教学模型上海康人医学仪器设备有限公司 | 大数据营销公司_舆情监测软件_上海SEO公司-文军营销官网 | 台湾HIWIN上银直线模组|导轨滑块|TBI滚珠丝杆丝杠-深圳汉工 | 河北码上网络科技|邯郸小程序开发|邯郸微信开发|邯郸网站建设 | 集装箱展厅-住人集装箱住宿|建筑|房屋|集装箱售楼处-山东锐嘉科技工程有限公司 | 安驭邦官网-双向万能直角铣头,加工中心侧铣头,角度头[厂家直销] 闸阀_截止阀_止回阀「生产厂家」-上海卡比阀门有限公司 | 硫酸亚铁-聚合硫酸铁-除氟除磷剂-复合碳源-污水处理药剂厂家—长隆科技 | 淬火设备-钎焊机-熔炼炉-中频炉-锻造炉-感应加热电源-退火机-热处理设备-优造节能 | 重庆监控_电子围栏设备安装公司_门禁停车场管理系统-劲浪科技公司 | 英超直播_英超免费在线高清直播_英超视频在线观看无插件-24直播网 |