记录 VS 2012编译Qt 4.8.6

来源:互联网 发布:java实用教程 编辑:程序博客网 时间:2024/06/06 00:03

由于安装Vaa3D,需要编译Qt 4.8.6。 电脑中已装有VS 2012,就用它编译了。作为小白,碰到许多问题,现记录下来。


大致步骤:设置环境变量,添加路径 → 在VS命令提示中输入命令 → 出错时修改文件(可能会出现两次)→ 等待编译完成

工具:Microsoft Visual studio 2012,qt-opensource-windows-x86-vs2010-4.8.6.exe


详细过程:

1. 设置环境变量,添加路径

    打开 控制面板 → 系统 → 高级系统设置 → 环境变量 

    新建两条环境变量 

    QTDIR = C:\Qt\4.8.6
    QMAKESPEC = win32-msvc2012

    添加路径

    在PATH中加入C:\Qt\4.8.6\bin


2. 输入命令

    打开 VS2012 x64 本机工具命令提示(Open VS2012 x64 Native Tools Command Prompt ),输入:

  cd C:\Qt\4.8.6   configure -debug-and-release -opensource -platform win32-msvc2012

    当configure完成时,输入:

   nmake

    来进行编译。


注:如果有jom文件,可输入

   ..\jom\jom.exe -j N

来替代输入nmake指令,N代表核数,网络里说可以加速编译过程。


3. 出错时修改文件

    a. 出现如下错误时:

   .\wtf/HashSet.h(180) : error C2664: ‘std::pair<_Ty1,_Ty2>::pair(const std::pair<_Ty1,_Ty2> &)’ : cannot convert parameter 1 from    ‘std::pair<_Ty1,_Ty2>’to ‘const std::pair<_Ty1,_Ty2> &’ ......

修改文件C:\Qt\4.8.6\src\3rdparty\webkit\Source\JavaScriptCore\wtf\HashSet.h,将180行所在的函数和它下面的一个函数修改一下,原来的两个函数为:

    Template<typename T, typename U, typename V>    inline pair<typename HashSet<T, U, V>::iterator, bool> HashSet<T, U, V>::add(const ValueType& value)    {        return m_impl.add(value);    }    template<typename Value, typename HashFunctions, typename Traits>    template<typename T, typename HashTranslator>    inline pair<typename HashSet<Value, HashFunctions, Traits>::iterator, bool>    HashSet<Value, HashFunctions, Traits>::add(const T& value)    {        typedef HashSetTranslatorAdapter<ValueType, ValueTraits, T, HashTranslator> Adapter;        return m_impl.template addPassingHashCode<T, T, Adapter>(value, value);    }

修改后的函数为:

      template<typename T, typename U, typename V>    inline pair<typename HashSet<T, U, V>::const_iterator, bool> HashSet<T, U, V>::add(const ValueType&value)    {        auto p= m_impl.add(value);    return make_pair(typename HashSet<T, U, V>::const_iterator(p.first), p.second);    }    template<typename Value, typename HashFunctions, typename Traits>    template<typename T, typename HashTranslator>    inline pair<typename HashSet<Value, HashFunctions, Traits>::iterator, bool>    HashSet<Value, HashFunctions, Traits>::add(const T& value)    {        typedef HashSetTranslatorAdapter<ValueType, ValueTraits, T, HashTranslator> Adapter;    typedef typename HashSet<Value, HashFunctions, Traits>::iterator iter_type;    auto& temp = m_impl.template addPassingHashCode<T, T, Adapter>(value, value);        return make_pair((iter_type)temp.first, temp.second);    }

    b. 出现下面错误时,

   platform\DefaultLocalizationStrategy.cpp(327) : error C2001: newline in constant    platform\DefaultLocalizationStrategy.cpp(327) : fatal error C1057: unexpected end of file in macro expansion

修改文件C:\Qt\4.8.6\src\3rdparty\webkit\Source\WebCore\platform的第327行,是双引号引起的问题,修改后为:

  return WEB_UI_STRING("Look Up \"<selection>\"", "Look Up context menu item with selected word"). ......


注:也可在编译之前修改。


4. 等待编译完成

    编译过程很漫长,i5-3230M编译了近20个小时还没编译完成。。。


总结:

多查阅资料,注意关键词搜索,如:VS 2012编译Qt 4.8.6;error C2664;cannot convert parameter 1 from ‘std::pair<_Ty1,_Ty2>’to ‘const std::pair<_Ty1,_Ty2> 


参考文章

    http://blog.csdn.net/Form_/article/details/77489328

    https://wenku.baidu.com/view/776e4c4069eae009581bec6f.html

原创粉丝点击