如何使用 Visual C++ 2010 Express 从 32 位环境为 64 位 Windows 编译 Qt? [英] How to compile Qt for 64-bit Windows from a 32-bit environment with Visual C++ 2010 Express?

查看:25
本文介绍了如何使用 Visual C++ 2010 Express 从 32 位环境为 64 位 Windows 编译 Qt?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试为 64 位 Windows 编译 Qt 库(我不需要演示或示例).有说明此处,但我遇到了下面评论中描述的错误.似乎在任何地方都没有关于如何进行此过程的参考.

我的目标是 Microsoft Visual C++ 2010 Express.看起来我还需要 Perl 和 Windows SDK - 我该如何进行这个过程?

解决方案

这个过程相当乏味和耗时 - 但我会在这里详细解释每个步骤,以供将来尝试编译 Qt 的其他人使用.

  1. 第一步是安装所有先决条件.

    • ActivePerl,在配置过程中使用.安装 Perl 后需要重新启动,因为它会修改环境变量.
    • Windows SDK 7.1(以前称为平台 SDK).选择要安装的组件时,请务必包含 x64 库.

  2. Qt 下载页面下载 Qt 源存档.

  3. 将存档内容提取到易于记忆的位置(例如 C:).稍后您需要记住这个位置,因为我们将使用它来设置一些环境变量.

  4. 现在打开 Windows SDK 7.1 命令提示符.首先将环境设置为 32 位发布模式(我们需要将一些工具构建为 32 位应用程序):

    setenv/release/x86

  5. 设置以下环境变量(以下示例假设您已提取到 C:):

    set QTDIR=C:qt-everywhere-opensource-src-4.8.0设置 PATH=%PATH%;%QTDIR%in

  6. 现在运行 cd %QTDIR% 并指定配置选项 - 示例如下:

    configure -release -opensource -qt-zlib -qt-libpng -qt-libmng -qt-libtiff-qt-libjpeg -qt-style-windowsxp -qt-style-windowsvista -platformwin32-msvc2010

  7. 一旦配置过程完成,cdsrc目录并运行:

    qmake制作

    这个过程可能需要相当长的时间,所以现在是休息一下并回答 Stack Overflow 上的一些问题的好时机:)

  8. 工具现已构建,您需要将 Qt 编译为 64 位库.输入以下命令:

    setenv/x64

    您将需要再次设置步骤 5 中的环境变量.现在输入这些命令.

  9. 运行 cd %QTDIR% 然后重新运行 configure 命令确保指定一个附加选项:

    <前>配置 -release -opensource -qt-zlib -qt-libpng -qt-libmng -qt-libtiff-qt-libjpeg -qt-style-windowsxp -qt-style-windowsvista -platformwin32-msvc2010 -no-qmake

    -no-qmake 选项很重要——它表示我们要跳过qmake.exe 程序的编译,因为我们要保留 32-位版本.

  10. 由于一些依赖问题,现在事情变得非常复杂.Qt 构建核心库和其他一些组件所需的工具(如moc)在src.pro 文件中列为依赖项.这意味着编译器将尝试将它们构建为 64 位应用程序,然后尝试运行它们——这在 32 位系统上当然会失败.所以我们需要做的是编辑 src.pro 并自己删除这些依赖项.在第 85 行附近向下滚动并查找以以下内容开头的行:

    !wince*:!ordered:!symbian-abld:!symbian-sbsv2 {

    该部分中的每一行都列出了一个子目标及其依赖项.您现在要做的是删除所有以 src_tools_ 开头的依赖项.例如:

    src_gui.depends = src_corelib src_tools_uic

    变成:

    src_gui.depends = src_corelib

    可能有更好的方法,但我还没有想出来:)

  11. 现在我们cd再次进入src目录并运行以下命令

    nmake子winmain子corelib子xml子网络子sql子testlibsub-gui sub-qt3support sub-activeqt sub-opengl sub-xmlpatterns sub-phononsub-multimedia sub-svg sub-script sub-declarative sub-webkit子脚本工具子插件子导入

    构建 Qt 库并跳过工具依赖项.请注意,这也可能需要相当长的时间.

  12. 您现在应该在 lib 文件夹中有 64 位库,您可以在 64 位 Qt 应用程序中链接这些库.

<小时>

事实证明,即使这样还不够,因为我在链接 QtWebKit4.dll 库时仍然遇到了一些问题(与未解析符号有关).事实证明,其他人已经找到解决方案,需要将WebCore.pro中的QMAKE_HOST.arch改为QMAKE_TARGET.arch.

此外,上述选项将在不支持 OpenSSL 的情况下构建 QNetwork4.dll(您将无法通过 HTTPS 访问站点 - 即使在 QWebView 中).值得庆幸的是,这并不太难解决.为 Win64 下载并构建 OpenSSL 并将以下选项附加到步骤 #9 中的命令:

-openssl -I C:OpenSSLinc32 -L C:OpenSSLout32dll

(如果您在 C:OpenSSL 以外的其他地方安装了 OpenSSL,则必须更改路径.)

<小时>

进一步为了省去自己做这件事的麻烦,我把编译好的库上传到这里:
http://www.box.com/s/9710cbb278ef4890a7b5

I am trying to compile the Qt library (I don't need the demos or examples) for 64-bit Windows. There are instructions here but I run into the error described in the comment below it. There doesn't seem to be a reference anywhere for how one might go about doing this process.

I am targetting Microsoft Visual C++ 2010 Express. It looks like I need Perl and the Windows SDK as well - how do I go about this process?

解决方案

This process is quite tedious and time-consuming - but I will explain each step in detail here for the benefit of others who try to compile Qt in the future.

  1. The first step is to install all of the prerequisites.

    • ActivePerl, which is used during the configuration process. You will need to restart after installing Perl since it modifies environment variables.
    • The Windows SDK 7.1 (formerly called the Platform SDK). Be sure to include the x64 libraries when you select the components to install.

  2. Download the Qt source archive from the Qt Downloads page.

  3. Extract the contents of the archive to an easy-to-remember location (like C:). You need to remember this location later since we will be using it to set some environment variables.

  4. Now open the Windows SDK 7.1 Command Prompt. Begin by setting the environment to 32-bit release mode (we need to build some of the tools as 32-bit applications):

    setenv /release /x86
    

  5. Set the following environment variables (example below assumes you extracted to C:):

    set QTDIR=C:qt-everywhere-opensource-src-4.8.0
    set PATH=%PATH%;%QTDIR%in
    

  6. Now run cd %QTDIR% and specify the configuration options - example is included below:

    configure -release -opensource -qt-zlib -qt-libpng -qt-libmng -qt-libtiff
     -qt-libjpeg -qt-style-windowsxp -qt-style-windowsvista -platform
     win32-msvc2010
    

  7. Once the configuration process is complete, cd to the src directory and run:

    qmake
    nmake
    

    This process may take a considerable amount of time, so now would be a good time to take a break and answer some questions here on Stack Overflow :)

  8. The tools are now built and you need to compile Qt as a 64-bit library. Enter the following command:

    setenv /x64
    

    You will need to set the environment variables from step 5 again. Enter those commands now.

  9. Run cd %QTDIR% and then rerun the configure command being sure to specify one additional option:

    configure -release -opensource -qt-zlib -qt-libpng -qt-libmng -qt-libtiff
     -qt-libjpeg -qt-style-windowsxp -qt-style-windowsvista -platform
     win32-msvc2010 -no-qmake
    

    The -no-qmake option is very important - it indicates that we want to skip the compilation of the qmake.exe program because we want to keep the 32-bit version.

  10. Now things get really complicated here because of some dependency problems. The tools (like moc) that Qt needs to build the core library and some of the other components are listed as dependencies in the src.pro file. This means that the compiler will attempt to build them as 64-bit applications and then try to run them - which will of course fail on a 32-bit system. So what we need to do is edit src.pro and remove those dependencies ourselves. Scroll down near line 85 and look for a line that begins with:

    !wince*:!ordered:!symbian-abld:!symbian-sbsv2 {
    

    Each subsequent line in the section lists a sub-target and its dependencies. What you want to do now is remove all dependencies that begin with src_tools_. For example:

    src_gui.depends = src_corelib src_tools_uic
    

    Becomes:

    src_gui.depends = src_corelib
    

    There might be a better way of doing this, but I haven't figured it out yet :)

  11. Now we cd into the src directory once again and run the following command

    nmake sub-winmain sub-corelib sub-xml sub-network sub-sql sub-testlib
     sub-gui sub-qt3support sub-activeqt sub-opengl sub-xmlpatterns sub-phonon
     sub-multimedia sub-svg sub-script sub-declarative sub-webkit
     sub-scripttools sub-plugins sub-imports
    

    This builds only the Qt libraries and skips the tool dependencies. Note that this too may take a considerable amount of time.

  12. You should now have 64-bit libraries in the lib folder that you can link against in your 64-bit Qt applications.


Edit: it turns out that even this wasn't enough since I still ran into some problems when linking the QtWebKit4.dll library (something about unresolved symbols). It turns out that someone else has already found the solution and you need to change QMAKE_HOST.arch to QMAKE_TARGET.arch in WebCore.pro.

Also, the above options will build QNetwork4.dll without OpenSSL support (you won't be able to access sites over HTTPS - even in a QWebView). This, thankfully isn't too hard to fix. Download and build OpenSSL for Win64 and append the options below to the command in step #9:

-openssl -I C:OpenSSLinc32 -L C:OpenSSLout32dll

(You'll have to change the paths if you installed OpenSSL somewhere other than C:OpenSSL.)


Further edit: to save the trouble of doing this yourself, I have uploaded the compiled libraries here:
http://www.box.com/s/9710cbb278ef4890a7b5

这篇关于如何使用 Visual C++ 2010 Express 从 32 位环境为 64 位 Windows 编译 Qt?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆