本文介绍了如何在Windows或Linux下编译Qt 5,32或64位,在VS2010,VS2012,VS2013或VS2015 Express或g ++上静态或动态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只是一个职位,帮助那些家伙试图这样做,因为我没有一个博客。



这也适用于linux。

解决方案

注意:还有另一篇文章我写到



9。




  • 对于VS2012:对VS2012执行以下命令

      set QMAKESPEC = win32-msvc2012 
    set QTDIR = C:\Qt\Qt5.7\qtbase
    set PATH = C:\Qt\Qt5.7\qtbase\bin;%PATH%

    对于动态链接(需要8 GB)

     配置-debug-and-release -opensource -platform win32-msvc2012 -opengl桌面

    用于没有示例的动态链接(需要2 GB)

     配置-debug-and-release -opensource -platform win32-msvc2012 -opengl桌面-nomake示例-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示例-nomake tests 

    或两个,那么使用jom如下(假设它在C:\Qt\jom中提取):

      C: \\ Qt \jom\jom.exe -j 50 

    50表示您想要的核心数使用。我使用50,因为我有8个线程,只使用8将不会占据所有的核心完全,所以更多是更好,但不要太贪婪,因为它可以使您的系统不响应。


  • 对于VS2010:对VS2010执行以下命令

     设置QMAKESPEC = win32-msvc2010 
    set QTDIR = C:\Qt\Qt5.7\qtbase
    set PATH = C:\Qt\Qt5.7\qtbase\bin;%PATH %

    用于动态链接(需要8 GB)

      configure -debug-and-release -opensource -platform win32-msvc2010 -opengl desktop 

    对于没有示例的动态链接(需要2 GB)

      configure -debug-and-release -opensource -platform win32-msvc2010 -opengl桌面-nomake示例-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示例-nomake tests 

    或两个,那么使用jom如下(假设它在C:\Qt\jom中提取):

      C: \\ Qt \jom\jom.exe -j 50 

    50表示您想要的核心数使用。我使用50,因为我有8个线程,只使用8将不会占据所有的核心完全,所以更多是更好,但不要太贪婪,因为它可以使您的系统不响应。


  • 对于linux:




Windows上的Linux。建议在linux中编译后安装 。老实说,这是它为我工作的唯一方式没有问题。



对于Linux执行以下命令。不要忘记用您的Qt源的正确路径替换路径

  export QMAKESPEC = linux-g ++ 
export QTDIR = / home / username / Qt5.7 / qtbase
export PATH = / home / username / Qt5.7 / qtbase / bin:$ PATH

假设您要将编译的源安装到目录 /home/username/Qt5.7-install 。在这种情况下,将以下内容添加到以下配置命令的任何中:

 `-prefix / home / username / Qt5.7-install` 

警告:安装到同一个源目录。这是纯粹的错误!



如果未设置 -prefix ,将选择默认路径, c $ c> / usr / local / 我猜。我不喜欢使用root安装任何东西。我总是喜欢在我的用户文件夹中安装,以便可逆性和升级不是问题。



以下是不同的可能配置

对于动态链接(需要8 GB)

  ./ configure -debug-and-release -opensource -platform linux-g ++ -opengl desktop 

对于没有示例的动态链接(需要2 GB)

  ./ configure -debug-发布-opensource -platform linux-g ++ -opengl桌面-nomake示例-nomake测试

取决于你想要编译的内容。只需键入 ./ 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示例-nomake tests 

完成后,运行make command



  make -j 50 

50表示要使用的核心数。我使用50因为我有8个线程,使用只有8将不会占用所有的核心完全,所以更多是更好,但不要太贪婪,因为它可以使您的系统不响应。


  1. 等待2+小时,直到编译完成。


  2. !你可以使用这个命令为Windows保存大量的空间:
    C:\Qt\jom\jom.exe clean 这个命令为linux: make clean


文件夹从8 GB到2.5 GB(用于动态链接)和从70 GB到35 GB(用于静态链接)。






为了在Qt Creator中使用此编译版本:


  1. 启动Qt Creator

  2. 前往工具,选项

  3. 从左侧列表中选择生成并运行。

  4. 转到Qt版本标签

  5. 点击添加,然后从
    qtbase中的文件夹中选择qmake,因此从上面:



    C:\Qt\Qt5.7\qtbase\bin\qmake.exe


(或对于Linux选择安装编译的Qt源的路径,这相当于 /home/username/Qt5.7-install/qtbase/bin/qmake 在本教程中)


  1. 点击应用
  2. 转到Kits标签

  3. 点击添加。

  4. 给它一个名字,选择合适的编译器(FOR VISUAL STUDIO
    EXPRESS不要为64位选择amd64,它将不工作,请选择
    x86_amd64 INSTEAD)

  5. 单击确定。



    1. 现在只要打开一个项目,你会发现它要求你选择你添加的套件。



      享受: )


      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:\Qt\Qt5.6, so now the folder qtbase can be found in C:\Qt\Qt5.6\qtbase .

      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: qtbase\mkspecs\win32-msvc2012\qmake.conf

        • b. For VS2010: qtbase\mkspecs\win32-msvc2010\qmake.conf

        • c. For Qt 5.5.0 and later (with any VS version): qtbase\mkspecs\common\msvc-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
        

      8. 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:\Qt\Qt5.7\qtbase
         set PATH=C:\Qt\Qt5.7\qtbase\bin;%PATH%
        

        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:\Qt\jom):

          C:\Qt\jom\jom.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:\Qt\Qt5.7\qtbase
        set PATH=C:\Qt\Qt5.7\qtbase\bin;%PATH%
        

        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
        

        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-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:\Qt\jom):

         C:\Qt\jom\jom.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
      

      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:\Qt\jom\jom.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 inqtbase is, so from above:

        C:\Qt\Qt5.7\qtbase\bin\qmake.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 STUDIOEXPRESS DO NOT SELECT amd64 FOR 64-BIT , IT WON'T WORK, CHOOSEx86_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下编译Qt 5,32或64位,在VS2010,VS2012,VS2013或VS2015 Express或g ++上静态或动态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 06:36