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 ()?環形?)
主站蜘蛛池模板: 心得体会网_心得体会格式范文模板 | 洛阳装修公司-洛阳整装一站式品牌-福尚云宅装饰 | 「阿尔法设计官网」工业设计_产品设计_产品外观设计 深圳工业设计公司 | 临沂招聘网_人才市场_招聘信息_求职招聘找工作请认准【马头商标】 | 天津散热器_天津暖气片_天津安尼威尔散热器制造有限公司 | ★塑料拖链__工程拖链__电缆拖链__钢制拖链 - 【上海闵彬】 | 河南膏药贴牌-膏药代加工-膏药oem厂家-洛阳今世康医药科技有限公司 | 深圳市人通智能科技有限公司| 杭州火蝠电商_京东代运营_拼多多全托管代运营【天猫代运营】 | 珠光砂保温板-一体化保温板-有釉面发泡陶瓷保温板-杭州一体化建筑材料 | 澳洁干洗店加盟-洗衣店干洗连锁「澳洁干洗免费一对一贴心服务」 干洗加盟网-洗衣店品牌排行-干洗设备价格-干洗连锁加盟指南 | 北京公司注册_代理记账_代办商标注册工商执照-企力宝 | 电动车头盔厂家_赠品头盔_安全帽批发_山东摩托车头盔—临沂承福头盔 | 安平县鑫川金属丝网制品有限公司,防风抑尘网,单峰防风抑尘,不锈钢防风抑尘网,铝板防风抑尘网,镀铝锌防风抑尘网 | 蒸压釜_蒸养釜_蒸压釜厂家-山东鑫泰鑫智能装备有限公司 | 品牌策划-品牌设计-济南之式传媒广告有限公司官网-提供品牌整合丨影视创意丨公关活动丨数字营销丨自媒体运营丨数字营销 | PAS糖原染色-CBA流式多因子-明胶酶谱MMP-上海研谨生物科技有限公司 | 压片机_高速_单冲_双层_花篮式_多功能旋转压片机-上海天九压片机厂家 | 土壤墒情监测站_土壤墒情监测仪_土壤墒情监测系统_管式土壤墒情站-山东风途物联网 | 数显水浴恒温振荡器-分液漏斗萃取振荡器-常州市凯航仪器有限公司 | 基业箱_环网柜_配电柜厂家_开关柜厂家_开关断路器-东莞基业电气设备有限公司 | 青岛代理记账_青岛李沧代理记账公司_青岛崂山代理记账一个月多少钱_青岛德辉财税事务所官网 | 税筹星_灵活用工平台_企业财务顾问_财税法薪综合服务平台 | 安规_综合测试仪,电器安全性能综合测试仪,低压母线槽安规综合测试仪-青岛合众电子有限公司 | elisa试剂盒价格-酶联免疫试剂盒-猪elisa试剂盒-上海恒远生物科技有限公司 | DWS物流设备_扫码称重量方一体机_快递包裹分拣机_广东高臻智能装备有限公司 | 礼仪庆典公司,礼仪策划公司,庆典公司,演出公司,演艺公司,年会酒会,生日寿宴,动工仪式,开工仪式,奠基典礼,商务会议,竣工落成,乔迁揭牌,签约启动-东莞市开门红文化传媒有限公司 | 加中寰球移民官网-美国移民公司,移民机构,移民中介,移民咨询,投资移民 | 意大利Frascold/富士豪压缩机_富士豪半封闭压缩机_富士豪活塞压缩机_富士豪螺杆压缩机 | 砍排机-锯骨机-冻肉切丁机-熟肉切片机-预制菜生产线一站式服务厂商 - 广州市祥九瑞盈机械设备有限公司 | 散热器厂家_暖气片_米德尔顿散热器| 丹尼克尔拧紧枪_自动送钉机_智能电批_柔性振动盘_螺丝供料器品牌 | 光伏家 - 太阳能光伏发电_分布式光伏发电_太阳能光伏网 | 珠海白蚁防治_珠海灭鼠_珠海杀虫灭鼠_珠海灭蟑螂_珠海酒店消杀_珠海工厂杀虫灭鼠_立净虫控防治服务有限公司 | 在线浊度仪_悬浮物污泥浓度计_超声波泥位计_污泥界面仪_泥水界面仪-无锡蓝拓仪表科技有限公司 | 异噻唑啉酮-均三嗪-三丹油-1227-中北杀菌剂厂家 | 聚合氯化铝厂家-聚合氯化铝铁价格-河南洁康环保科技 | 并网柜,汇流箱,电控设备,中高低压开关柜,电气电力成套设备,PLC控制设备订制厂家,江苏昌伟业新能源科技有限公司 | 闪电优家-卫生间防水补漏_酒店漏水渗水维修_防水堵漏公司 | 餐饮加盟网_特色餐饮连锁加盟店-餐饮加盟官网 | 合景一建-无尘车间设计施工_食品医药洁净车间工程装修总承包公司 |