QT备忘录之七:loongarch64+loongnix20.3静态编译qt5.9.1

一切问题都源于loongarch没有写到qt的架构支持清单里,比想象中的简单。

0. 写在前面

源代码不要解压到带有中文的路径下,否则可能在configure时导致“找不到xxx文件”错误。

1. configure

我使用如下的的配置参数。

[code lang="cpp" collapse="false"]
sudo ./configure -confirm-license -opensource -platform linux-g++ -static -prefix "/home/SourceCode/qt-everywhere-opensource-src-5.9.1/prefix" -plugin-sql-sqlite -qt-zlib -qt-libpng -qt-libjpeg -opengl desktop -qt-freetype -no-qml-debug -no-angle -no-compile-examples -nomake tools -nomake tests -nomake examples -skip qtwebkit
[/code]

具体参数不再解释了,请参考之前的文章,或者Qt官方文档(http://doc.qt.io/qt-5.6/configure-options.htmlhttp://doc.qt.io/qt-4.8/configure-options.html),在此不再赘述。

如果configure成功,会有如下提示:

configure成功

2. 问题终于来了

但是,在loongarch64架构下,你一定不能一蹴而就,百分之两千会遇到如下的报错

error: #error Target architecture was not detected as supported by Double-Conversion

这个报错指向qt-everywhere-opensource-src-5.9.1/qtbase/src/3rdparty/double-conversion/include/double-conversion/utils.h

此文件60行开始是对各种架构的定义,显见没有loongarch或者类似的表述

[code lang="cpp" collapse="false"]
#if defined(_M_X64) || defined(__x86_64__) || \
defined(__ARMEL__) || defined(__avr32__) || _M_ARM_FP || \
defined(__hppa__) || defined(__ia64__) || \
defined(__mips__) || \
defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__) || \
defined(__sparc__) || defined(__sparc) || defined(__s390__) || \
defined(__SH4__) || defined(__alpha__) || \
defined(_MIPS_ARCH_MIPS32R2) || \
defined(__AARCH64EL__)
#define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1
#elif defined(_M_IX86) || defined(__i386__) || defined(__i386)
#if defined(_WIN32)
// Windows uses a 64bit wide floating point stack.
#define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1
#else
#undef DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS
#endif // _WIN32
#elif defined(__ghs)
// Green Hills toolchain uses a 64bit wide floating point stack
#define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1
#else
#error Target architecture was not detected as supported by Double-Conversion.
#endif
[/code]

好在当前版本的loongnix系统已经更新了config.guess和config.sub文件,相关的架构已经在文件中列明。因此,此处只需增加一个defined(__loongarch__) 。loongarch目前没有32位版本,因此__loongarch64__与__loongarch__是直接等价的。更改后的部分如下,也可以点这里下载更改过的版本。

[code lang="cpp" collapse="false"]
#if defined(_M_X64) || defined(__x86_64__) || \
defined(__ARMEL__) || defined(__avr32__) || _M_ARM_FP || \
defined(__hppa__) || defined(__ia64__) || \
defined(__mips__) || defined(__loongarch__) || \
defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__) || \
defined(__sparc__) || defined(__sparc) || defined(__s390__) || \
defined(__SH4__) || defined(__alpha__) || \
defined(_MIPS_ARCH_MIPS32R2) || \
defined(__AARCH64EL__)
#define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1
#elif defined(_M_IX86) || defined(__i386__) || defined(__i386)
#if defined(_WIN32)
// Windows uses a 64bit wide floating point stack.
#define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1
#else
#undef DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS
#endif // _WIN32
#elif defined(__ghs)
// Green Hills toolchain uses a 64bit wide floating point stack
#define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1
#else
#error Target architecture was not detected as supported by Double-Conversion.
#endif
[/code]

3. make和install

[code lang="cpp" collapse="false"]
sudo make -j4
sudo make install
[/code]

这里往后就没什么神奇的了。

 

二零二三年三月二日

顾毅 写于厦门