当前位置: 首页 > article >正文

龙芯 Loongson 架构 UOS 系统编译 Qt 5.15.2 源码

背景

需要在龙芯(Loongson)CPU,UOS 系统下,进行国产化项目适配,UOS 自带 Qt 5.11,但是版本过老,与目前基于 Qt 5.15.2 项目存在不兼容情况,故需要自行编译 Qt 5.15.2开发环境。

软硬件信息:

  • 处理器:Loongson-3A5000 (四核 / 四逻辑处理器)
  • 主板:Loongson-LS 3A5000-7A 1000-1w-V0.1-CRB
  • 架构:loongarch 64
  • 家族:Loongson-64 bit
  • 系统:UOS V20 1060
  • 内核: 4.19.0-loongson-3-desktop

下载 Qt 源码

这里使用国内的镜像地址下载源码

Qt 5.15.2: http://mirrors.ustc.edu.cn/qtproject/archive/qt/5.15/5.15.2/single/

由于龙芯 3A5000 CPU 采用了全新的 LoongArch 架构,所以直接编译 Qt 源码通常会有问题,尤其是 QWebEngine 不支持 LoongArch 架构。不过,可能高版本会好些,我编译 5.15.9 版本一次编译通过,而 5.15.2 编译的时候就 Segmentation fault

所以需要向龙芯那边的人,要来针对 LoongArch 适配的 Qt 源码包,通常是有 patch 的源码包。然后使用提供的这个源码包进行编译即可,不过截止此文发表时间 2023-11-12,龙芯那边只有 Qt 5.15.2 的包,如果是其他版本,可能需要自行打 patch 适配了。

打 patch

以 QWebEngine 为例,演示如何打 patch:

$ ls
qtwebengine-opensource-src_5.15.2+dfsg-lnd.3.debian.tar.xz  qtwebengine-opensource-src_5.15.2+dfsg-lnd.3.dsc  qtwebengine-opensource-src_5.15.2+dfsg.orig.tar.xz

将这三个包放在同一目录下,含有 debian 字样的文件就是 patch 包。

然后使用命令自动解压并打 patch:

$ dpkg-source -x *.dsc
dpkg-source: warning: extracting unsigned source package (qtwebengine-opensource-src_5.15.2+dfsg-lnd.3.dsc)
dpkg-source: info: extracting qtwebengine-opensource-src in qtwebengine-opensource-src-5.15.2+dfsg
dpkg-source: info: unpacking qtwebengine-opensource-src_5.15.2+dfsg.orig.tar.xz
dpkg-source: info: unpacking qtwebengine-opensource-src_5.15.2+dfsg-lnd.3.debian.tar.xz
dpkg-source: info: using patch list from debian/patches/series
dpkg-source: info: applying run-unbundling-script.patch
dpkg-source: info: applying system-lcms2.patch
dpkg-source: info: applying system-nspr-prtime.patch
dpkg-source: info: applying system-icu-utf.patch
dpkg-source: info: applying verbose-gn-bootstrap.patch
dpkg-source: info: applying mipsel-linux-5.patch
dpkg-source: info: applying mipsel-ptrace-include.patch
dpkg-source: info: applying mipsel-no-dav1d.patch
dpkg-source: info: applying mipsel-link-atomic.patch
dpkg-source: info: applying sandbox-time64-syscalls.patch
dpkg-source: info: applying mipsel-code-range-size.patch
dpkg-source: info: applying 0001-port-chromium_qt-to-loongarch64.patch
dpkg-source: info: applying 0002-fix-third_party-for-loongarch64.patch
dpkg-source: info: applying 0003-port-breakpad-for-loongarch64.patch
dpkg-source: info: applying 0004-port-ffmpeg-to-loongarch64-for-chromium.patch
dpkg-source: info: applying 0005-port-ffmpeg-to-loongarch64-for-chromium-add-la64-rel.patch
dpkg-source: info: applying 0006-fix-third_party-for-loongarch64-add-files-for-la64.patch
dpkg-source: info: applying 0007-port-icu-for-loongarch64.patch
dpkg-source: info: applying 0008-port-lss-for-loongarch64.patch
dpkg-source: info: applying 0009-port-pdfium-for-loongarch64.patch
dpkg-source: info: applying 0010-port-swiftshader-for-loongarch64.patch
dpkg-source: info: applying 0011-port-webrtc-for-loongarch64.patch
dpkg-source: info: applying 0012-port-v8-for-loongarch64.patch
dpkg-source: info: applying 0013-make-qtwebengine-can-be-compiled-for-loongarch64.patch
dpkg-source: info: applying 0014-fix-compile-errors-for-mips64el.patch
dpkg-source: info: applying 0015-fix-compiler-internal-error-for-loongarch64.patch
dpkg-source: info: applying 0016-fix-compile-error-for-loongarch64.patch

可以看到,patch 已经自动打好了,并在 qtwebengine-opensource-src-5.15.2+dfsg 目录下

$ ls
qtwebengine-opensource-src-5.15.2+dfsg  qtwebengine-opensource-src_5.15.2+dfsg-lnd.3.debian.tar.xz  qtwebengine-opensource-src_5.15.2+dfsg-lnd.3.dsc  qtwebengine-opensource-src_5.15.2+dfsg.orig.tar.xz

但是,龙芯提供的源码包有文件缺失的情况,这个后面编译时会遇到对应的错误。

环境配置

安装 Qt 所需的依赖:

sudo apt install build-essential libgl1-mesa-dev libxkbcommon-dev libnss3-dev libdbus-1-dev gperf flex bison

安装 xcb 相关:

sudo apt-get install '^libxcb.*-dev' libx11-xcb-dev libglu1-mesa-dev libxrender-dev libxi-dev libxkbcommon-dev libxkbcommon-x11-dev

这一步比较关键,因为涉及到编译之后有 libqxcb.so,如果缺失会导致错误。

如果需要使用到 QWebEngine 模块,那么需要安装以下依赖库:

sudo apt install libxcursor-dev libxcomposite-dev libxdamage-dev libxrandr-dev libxtst-dev libxss-dev libdbus-1-dev libevent-dev libfontconfig1-dev libcap-dev libpulse-dev libudev-dev libpci-dev libnss3-dev libasound2-dev libegl1-mesa-dev gperf bison nodejs

编译 Qt

进入解压后的 qt-everywhere-src-5.15.2 目录,开始配置:

./configure -prefix /home/leo/Qt -opensource -confirm-license -nomake examples -release
  • -prefix /home/leo/Qt: 指定 Qt 的安装路径
  • -opensource: 指定使用开源版本
  • -nomake examples: 不编译 examples
  • -release: release 模式

这个步骤会检查相关的库是否存在,若不存在则将缺少的安装。
安装完缺失的依赖库后,记得先删除 config.cache 缓存文件。

或者使用脚本运行,创建 run.sh 脚本:

#! /bin/bash
./configure -prefix /home/leo/Qt/5 \
-opensource -confirm-license \
-nomake examples \
-nomake tests \
-release \
-skip qt3d \
-skip qtcharts \
-skip qtandroidextras \
-skip qtlocation \
-skip qtmultimedia \
-skip qtsensors \
-skip qtserialbus \
-skip qtserialport \
-skip qtwayland

可以指定跳过编译哪些模块以加快编译速度,如果你不需要 QWebEngine,那么推荐跳过编译,这样能大幅加快编译速度,同时能避免因 QWebEngine 导致的编译错误。

开始编译:

make

在编译过程中,可能会遇到一些依赖问题,需要根据实际情况进行解决。

编译完成后即可安装

make install

编译 QWebEngine(可选)

编译 QWebEngine 这一步是因为需要开启音视频功能,支持 H264 编码格式等。

配置编译好的 Qt 环境到 .bashrc,之后创建 build 文件夹,执行命令:

qmake ../qtwebengine.pro -- -webengine-proprietary-codecs
make

输出信息:

g++ -Wl,--no-undefined -Wl,--version-script,QtPdfWidgets.version -Wl,-O1 -Wl,--enable-new-dtags -Wl,-z,origin -Wl,-rpath,\$ORIGIN -Wl,-rpath-link,/home/geit/Qt/5.15.2/lib -shared -Wl,-soname,libQt5PdfWidgets.so.5 -o libQt5PdfWidgets.so.5.15.2 .obj/qpdfview.o  /home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/build/lib/libQt5Pdf.so /home/geit/Qt/5.15.2/lib/libQt5Widgets.so /home/geit/Qt/5.15.2/lib/libQt5Gui.so /home/geit/Qt/5.15.2/lib/libQt5Core.so -lpthread -lGL   
ln -s libQt5PdfWidgets.so.5.15.2 libQt5PdfWidgets.so
ln -s libQt5PdfWidgets.so.5.15.2 libQt5PdfWidgets.so.5
ln -s libQt5PdfWidgets.so.5.15.2 libQt5PdfWidgets.so.5.15
rm -f ../../lib/libQt5PdfWidgets.so.5.15.2
mv -f libQt5PdfWidgets.so.5.15.2 ../../lib/libQt5PdfWidgets.so.5.15.2
rm -f ../../lib/libQt5PdfWidgets.so
rm -f ../../lib/libQt5PdfWidgets.so.5
rm -f ../../lib/libQt5PdfWidgets.so.5.15
mv -f libQt5PdfWidgets.so ../../lib/libQt5PdfWidgets.so
mv -f libQt5PdfWidgets.so.5 ../../lib/libQt5PdfWidgets.so.5
mv -f libQt5PdfWidgets.so.5.15 ../../lib/libQt5PdfWidgets.so.5.15
make[2]: 离开目录“/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/build/src/pdfwidgets”
make[1]: 离开目录“/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/build/src”

编译完之后,就可以安装到 Qt 的路径下:

$ make install

geit@geit:~/Documents/qtwebengine-opensource-src-5.15.2+dfsg/build$ make install
cd src/ && ( test -e Makefile || /home/geit/Qt/5.15.2/bin/qmake -o Makefile /home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/src.pro ) && make -f Makefile install
make[1]: 进入目录“/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/build/src”

....

make[2]: 进入目录“/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/build/src/core”
( test -e Makefile.core_headers || /home/geit/Qt/5.15.2/bin/qmake -o Makefile.core_headers /home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/core/core_headers.pro ) && make -f Makefile.core_headers install
make[3]: 进入目录“/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/build/src/core”
sed  -e 's,/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/build/lib,$$[QT_INSTALL_LIBS],g' -e 's,/home/geit/Qt/5.15.2/lib,$$[QT_INSTALL_LIBS],g' ../../lib/libQt5WebEngineCore.prl > /home/geit/Qt/5.15.2/lib/libQt5WebEngineCore.prl
sed  -e s,/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/build/lib,=/home/geit/Qt/5.15.2/lib,g ../../lib/Qt5WebEngineCore.la > /home/geit/Qt/5.15.2/lib/Qt5WebEngineCore.la
/home/geit/Qt/5.15.2/bin/qmake -install qinstall /home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/include/QtWebEngineCore/QWebEngineCallback /home/geit/Qt/5.15.2/include/QtWebEngineCore/QWebEngineCallback

错误解决

如果没看到错误,可以使用 make -j1 单进程编译,然后错误信息就能看到了。

  1. 找不到 sqlite3.h 头文件
/home/geit/Documents/qt-everywhere-src-5.15.2/qtbase/src/plugins/sqldrivers/sqlite/qsql_sqlite.cpp:66:10: fatal error: sqlite3.h: 没有那个文件或目录
#include <sqlite3.h>

这个问题,就是因为龙芯提供的 qtbase 源码包有 debian rules 文件,rules 里做了一些修改,指定使用系统的 sqlite。可以将 qt-everywhere-src-5.15.2 里的 qtbase 拷贝到目前的编译目录,最好使用文件管理器进行,因为可以选择合并,跳过替换,这样就相当于只把缺失的文件给拷贝过来了。

  1. error: cast from ‘QTJSC::JSCell*’ to ‘int32_t’ {aka ‘int’} loses precision
/home/geit/Documents/qt-everywhere-src-5.15.2/qtscript/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSValue.h: In constructor ‘QTJSC::JSValue::JSValue(QTJSC::JSCell*)’:
/home/geit/Documents/qt-everywhere-src-5.15.2/qtscript/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSValue.h:493:57: error: cast from ‘QTJSC::JSCell*’ to ‘int32_t’ {aka ‘int’} loses precision [-fpermissive]
         u.asBits.payload = reinterpret_cast<int32_t>(ptr);
                                                         ^
/home/geit/Documents/qt-everywhere-src-5.15.2/qtscript/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSValue.h: In constructor ‘QTJSC::JSValue::JSValue(const QTJSC::JSCell*)’:
/home/geit/Documents/qt-everywhere-src-5.15.2/qtscript/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSValue.h:505:78: error: cast from ‘QTJSC::JSCell*’ to ‘int32_t’ {aka ‘int’} loses precision [-fpermissive]
         u.asBits.payload = reinterpret_cast<int32_t>(const_cast<JSCell*>(ptr));
                                                                              ^
make[3]: *** [Makefile:3960:obj/release/JSBase.o] 错误 1

原因已经告诉你了,‘QTJSC::JSCell*’ 转’int 32_t’会丢失精度。
那么我们打开这个文件对应行,进行修改即可。

qt-everywhere-src-5.15.2/qtscript/src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSValue.h 跳转到 493 行和 505 行,把 int_32_t 改成 int 64_t 即可:

u.asBits.payload=reinterpret_cast<int32_t>(ptr); -> u.asBits.payload=reinterpret_cast<int64_t>(ptr);
u.asBits.payload=reinterpret_cast<int_32_t>(const_cast<JSCell*>(ptr)); -> u.asBits.payload=reinterpret_cast<int64_t>(const_cast<JSCell*>(ptr));
ninja: Entering directory `/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/build/src/core/release'
ninja: error: '../../../../src/3 rdparty/chromium/third_party/devtools-frontend/src/front_end/third_party/lighthouse/lighthouse-dt-bundle. js', needed by 'resources/inspector/root. js', missing and no known rule to make it
make[3]: *** [Makefile. gn_run:460:run_ninja] 错误 1

遇到这个错误是因为,debain rules 把这些文件删除了,可以从qt-everywhere-src-5.15.2/qtwebengine/src/3 rdparty/chromium/third_party/devtools-frontend/src/front_end/third_party/lighthouse/路径下将缺失的文件拷贝过去即可

ninja: Entering directory `/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/build/src/core/release'
ninja: error: '../../../../src/3 rdparty/chromium/third_party/devtools-frontend/src/front_end/third_party/lighthouse/report-assets/report-generator. js', needed by 'resources/inspector/root. js', missing and no known rule to make it
make[3]: *** [Makefile. gn_run:460:run_ninja] 错误 1

问题同上,解决方案也是一致,拷贝缺失的文件

/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/build/src/3 rdparty/ninja/ninja -v  -C /home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/build/src/core/release QtWebEngineCore
ninja: Entering directory `/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/build/src/core/release'
ninja: error: '../../../../src/3 rdparty/chromium/third_party/devtools-frontend/src/front_end/diff/diff_match_patch. js', needed by 'resources/inspector/root. js', missing and no known rule to make it
make[3]: *** [Makefile. gn_run:460:run_ninja] 错误 1

问题同上,解决方案也是一致,拷贝缺失的文件

简便方法:可以直接将qt-everywhere-src-5.15.2/qtwebengine/src/3 rdparty/chromium/third_party/devtools-frontend/src路径下的文件全都拷贝过去

<structure compress="gzip" file="../../../third_party/web-animations-js/sources/web-animations-next-lite.min.js" name="IDR_POLYMER_1_0_WEB_ANIMATIONS_JS_WEB_ANIMATIONS_NEXT_LITE_MIN_JS" type="chrome_html" />: [Errno 2] No such file or directory: '/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/third_party/web-animations-js/sources/web-animations-next-lite. min. js'
Traceback (most recent call last):
  File "../../../../src/3 rdparty/chromium/tools/grit/grit. py", line 29, in <module>
    sys.exit (grit. grit_runner.Main (sys. argv[1:]))
  File "/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/tools/grit/grit/grit_runner. py", line 314, in Main
    return toolobject.Run (options, args[1:])
  File "/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/tools/grit/grit/tool/build. py", line 266, in Run
    self.res.RunGatherers ()
  File "/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/tools/grit/grit/node/misc. py", line 665, in RunGatherers
    node.RunPreSubstitutionGatherer (debug=debug)
  File "/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/tools/grit/grit/node/structure. py", line 240, in RunPreSubstitutionGatherer
    self.gatherer.Parse ()
  File "/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/tools/grit/grit/gather/chrome_html. py", line 374, in Parse
    util.ReadFile (filename, 'utf-8'),
  File "/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/tools/grit/grit/util. py", line 216, in ReadFile
    with io.open (abs (filename), mode, encoding=encoding) as f:
IOError: [Errno 2] No such file or directory: '/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/third_party/web-animations-js/sources/web-animations-next-lite. min. js'

很明显,web-animations-js 库文件缺失。

<structure compress="gzip" file="../../../third_party/polymer/v3_0/components-chromium/polymer/polymer_bundled.min.js" name="IDR_POLYMER_3_0_POLYMER_POLYMER_BUNDLED_MIN_JS" type="chrome_html" />: [Errno 2] No such file or directory: '/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/third_party/polymer/v 3_0/components-chromium/polymer/polymer_bundled. min. js'
Traceback (most recent call last):
  File "../../../../src/3 rdparty/chromium/tools/grit/grit. py", line 29, in <module>
    sys.exit (grit. grit_runner.Main (sys. argv[1:]))
  File "/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/tools/grit/grit/grit_runner. py", line 314, in Main
    return toolobject.Run (options, args[1:])
  File "/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/tools/grit/grit/tool/build. py", line 266, in Run
    self.res.RunGatherers ()
  File "/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/tools/grit/grit/node/misc. py", line 665, in RunGatherers
    node.RunPreSubstitutionGatherer (debug=debug)
  File "/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/tools/grit/grit/node/structure. py", line 240, in RunPreSubstitutionGatherer
    self.gatherer.Parse ()
  File "/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/tools/grit/grit/gather/chrome_html. py", line 374, in Parse
    util.ReadFile (filename, 'utf-8'),
  File "/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/tools/grit/grit/util. py", line 216, in ReadFile
    with io.open (abs (filename), mode, encoding=encoding) as f:
IOError: [Errno 2] No such file or directory: '/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/third_party/polymer/v 3_0/components-chromium/polymer/polymer_bundled. min. js'

这次是 polymer 缺失文件

FAILED: gen/ui/resources/webui_resources_grd_grit. d. stamp gen/ui/resources/grit/webui_resources. h gen/ui/resources/grit/webui_resources_map. cc gen/ui/resources/grit/webui_resources_map. h gen/ui/resources/webui_resources. pak gen/ui/resources/webui_resources. pak. info 
/usr/bin/python 2 ../../../../src/3 rdparty/chromium/tools/grit/grit. py -i ../../../../src/3 rdparty/chromium/ui/webui/resources/webui_resources. grd build -o gen/ui/resources --depdir . --depfile gen/ui/resources/webui_resources_grd_grit. d --write-only-new=1 --depend-on-stamp -D scale_factors=2 x -D _chromium -E CHROMIUM_BUILD=chromium -D desktop_linux -D use_aura -D use_nss_certs -D use_ozone -t linux 2 -D optimize_webui=false -E root_gen_dir=gen -f gen/tools/gritsettings/default_resource_ids --assert-file-list obj/ui/resources/webui_resources_grd_expected_outputs. txt
Error processing node <?xml version="1.0" encoding="UTF-8"?>
<include compress="gzip" file="js/jstemplate_compiled.js" flattenhtml="true" name="IDR_WEBUI_JSTEMPLATE_JS" type="BINDATA" />: Failed to open /home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/third_party/jstemplate/jstemplate_compiled. js while trying to flatten ../../../../src/3 rdparty/chromium/ui/webui/resources/js/jstemplate_compiled. js. (No such file or directory)
Traceback (most recent call last):
  File "../../../../src/3 rdparty/chromium/tools/grit/grit. py", line 29, in <module>
    sys.exit (grit. grit_runner.Main (sys. argv[1:]))
  File "/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/tools/grit/grit/grit_runner. py", line 314, in Main
    return toolobject.Run (options, args[1:])
  File "/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/tools/grit/grit/tool/build. py", line 274, in Run
    self.Process ()
  File "/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/tools/grit/grit/tool/build. py", line 409, in Process
    self.ProcessNode (self. res, output, tmpfile)
  File "/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/tools/grit/grit/tool/build. py", line 333, in ProcessNode
    formatted = formatter (node, output_node.GetLanguage (), output_dir=base_dir)
  File "/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/tools/grit/grit/format/data_pack. py", line 90, in Format
    value = node.GetDataPackValue (lang, util. BINARY)
  File "/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/tools/grit/grit/node/include. py", line 104, in GetDataPackValue
    data = self._GetFlattenedData (allow_external_script=allow_external_script)
  File "/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/tools/grit/grit/node/include. py", line 41, in _GetFlattenedData
    allow_external_script=allow_external_script))
  File "/home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/tools/grit/grit/format/html_inline. py", line 551, in InlineToString
    (e.filename, input_filename, e.strerror))
Exception: Failed to open /home/geit/Documents/qtwebengine-opensource-src-5.15.2+dfsg/src/3 rdparty/chromium/third_party/jstemplate/jstemplate_compiled. js while trying to flatten ../../../../src/3 rdparty/chromium/ui/webui/resources/js/jstemplate_compiled. js. (No such file or directory)

jstemplate 库文件缺失

/usr/bin/ld: 找不到 -llcms2
collect 2: error: ld returned 1 exit status
make[3]: *** [Makefile. core_module:90:../../lib/libQt 5 WebEngineCore. so. 5.15.2] 错误 1

安装

sudo apt install liblcms2-dev

其实这个也是由于 rules 文件导致的错误,它指定使用系统的 libcms2 库

文件缺失原因

rules

先附上 debian 文件夹下的 rules 文件:

#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1
export NINJA_PATH=/usr/bin/ninja
export NINJAFLAGS=-v
include /usr/share/dpkg/default. mk

DEB_HOST_ARCH_BITS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_BITS)

# TODO: properly integrate with the other debug setting
ifeq (32,$(DEB_HOST_ARCH_BITS))
       export DEB_CFLAGS_MAINT_APPEND = -g 1
       export DEB_CXXFLAGS_MAINT_APPEND = -g 1
endif

export CFLAGS := $(shell dpkg-buildflags --get CFLAGS) $(shell dpkg-buildflags --get CPPFLAGS)
export CXXFLAGS := $(shell dpkg-buildflags --get CXXFLAGS) $(shell dpkg-buildflags --get CPPFLAGS)
export LDFLAGS := $(shell dpkg-buildflags --get LDFLAGS)
export QT_SELECT := qt 5

VERSION_CLEAN_UPSTREAM = $(call dpkg_late_eval, VERSION_CLEAN_UPSTREAM, echo '$(DEB_VERSION_UPSTREAM)' | sed -e 's/\(~\|+\).*//')

DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

ifeq (yes,$(shell dpkg-vendor --derives-from Ubuntu && echo yes))
ifeq ($(DEB_HOST_ARCH), arm 64)
	export NINJAFLAGS += -j 2
endif
endif

gstab_architectures :=
fulldebug_architectures :=
disabled_jit_architectures := armel mips mipsel mips 64 el loongarch 64
disabled_pch_architectures := amd 64 powerpc s 390 x

small_architectures := armhf mipsel
no_gold_architectures := arm 64 armhf mipsel mips 64 el loongarch 64

config_args = -proprietary-codecs \
              -system-webp \

touch_files = src/3 rdparty/chromium/third_party/devtools-frontend/src/front_end/third_party/lighthouse/lighthouse-dt-bundle. js \
	      src/3 rdparty/chromium/third_party/devtools-frontend/src/front_end/third_party/lighthouse/report-assets/report-generator. js \
	      src/3 rdparty/chromium/third_party/devtools-frontend/src/front_end/diff/diff_match_patch. js \
	      src/3 rdparty/chromium/third_party/devtools-frontend/src/front_end/formatter_worker/acorn/acorn. js \
	      src/3 rdparty/chromium/third_party/polymer/v 3_0/components-chromium/polymer/polymer_bundled. min. js \
	      src/3 rdparty/chromium/third_party/web-animations-js/sources/web-animations-next-lite. min. js 

%:
	dh $@ --with pkgkde_symbolshelper

override_dh_auto_clean:
	dh_auto_clean
	rm -f .qmake. cache
	rm -f config. tests/. qmake. cache
	rm -f qtwebengine-config. h

	rm -rf $(CURDIR)/test_root
	rm -rf $(CURDIR)/docs
	rm -rf $(CURDIR)/. local
	rm -f $(CURDIR)/src/3 rdparty/chromium/third_party/jstemplate/jstemplate_compiled. js
	rm -f $(CURDIR)/src/3 rdparty/chromium/third_party/mocha/mocha. js
	rm -f $(CURDIR)/examples/webenginewidgets/contentmanipulation/jquery*. js

	for fname in $(touch_files); do \
		rm -f $(CURDIR)/$${fname}; \
	done

override_dh_auto_configure:
	# Run qmake once to create .qmake. conf and be sure to append the following values.
	qmake QT_BUILD_PARTS+=tests QMAKE_EXTRA_ARGS+="$(config_args)" QMAKE_PYTHON 2=python 2

# Enable gstabs debugging symbols only on gstab_architectures.
ifeq ($(DEB_HOST_ARCH),$(findstring $(DEB_HOST_ARCH), $(gstab_architectures)))
	echo "QMAKE_CXXFLAGS -= -g" >> .qmake. conf
	echo "QMAKE_CXXFLAGS += -gstabs" >> .qmake. conf
# Enable normal debugging symbols only on fulldebug_architectures.
else ifeq ($(DEB_HOST_ARCH),$(findstring $(DEB_HOST_ARCH), $(fulldebug_architectures)))
	echo "QMAKE_CXXFLAGS_DEBUG += -fdebug-types-section" >> .qmake. conf
	echo "QMAKE_CXXFLAGS += -fdebug-types-section" >> .qmake. conf
	echo "QMAKE_CXXFLAGS_RELEASE_WITH_DEBUGINFO += -fdebug-types-section" >> .qmake. conf
	echo "QMAKE_CXXFLAGS_RELEASE += -fdebug-types-section" >> .qmake. conf
	echo "QMAKE_LFLAGS += -fdebug-types-section" >> .qmake. conf
else
# Disable debugging symbols in all the other archs.
	echo "QMAKE_CFLAGS -= -g" >> .qmake. conf
	echo "QMAKE_CFLAGS -= -gstabs" >> .qmake. conf
	echo "QMAKE_CXXFLAGS -= -g" >> .qmake. conf
	echo "QMAKE_CXXFLAGS -= -gstabs" >> .qmake. conf
	echo "QT_CONFIG -= force_debug_info" >> .qmake. conf
	echo "QT_CONFIG -= separate_debug_info" >> .qmake. conf
endif

# Disable JIT on selected architectures
ifeq ($(DEB_HOST_ARCH),$(findstring $(DEB_HOST_ARCH), $(disabled_jit_architectures)))
	echo "QMAKE_CXXFLAGS += -DENABLE_JIT=0" >> .qmake. conf
endif

# Disable header precompliation as it creates invalid includes on certain
# architectures causing build failure. LP: 1395661
ifeq ($(DEB_HOST_ARCH),$(findstring $(DEB_HOST_ARCH), $(disabled_pch_architectures)))
	echo "CONFIG -= precompile_header" >> .qmake. conf
endif

ifeq ($(DEB_HOST_ARCH),$(findstring $(DEB_HOST_ARCH), $(small_architectures)))
	echo "QMAKE_CXXFLAGS += --param ggc-min-expand=20" >> .qmake. conf
	echo "QMAKE_CFLAGS += --param ggc-min-expand=20" >> .qmake. conf
	echo "QMAKE_LFLAGS -= Wl,--gc-sections" >> .qmake. conf
endif

ifeq ($(DEB_HOST_ARCH),$(findstring $(DEB_HOST_ARCH), $(no_gold_architectures)))
	# Do not use ld. gold
	echo "QMAKE_LFLAGS -= -fuse-ld=gold" >> .qmake. conf
	echo "QMAKE_LFLAGS += -fuse-ld=bfd" >> .qmake. conf
endif

	# Make ld not cache the symbol tables of input files in memory to avoid memory exhaustion during the linking phase.
	echo "QMAKE_LFLAGS += -Wl,--no-keep-memory" >> .qmake. conf

	# Missing hardening flag detected by blhc
	echo "QMAKE_LFLAGS += -Wl,-z, now" >> .qmake. conf

	# Run qmake again now with the proper values.
	qmake QT_BUILD_PARTS+=tests QMAKE_EXTRA_ARGS+="$(config_args)" QMAKE_PYTHON 2=python 2

	# Create js files, that are needed for building step for arch and indep builds
	cd $(CURDIR)/src/3 rdparty/chromium/third_party/jstemplate/; \
		closure-compiler --compilation_level ADVANCED_OPTIMIZATIONS \
		--js util. js \
		--js jsevalcontext. js \
		--js jstemplate. js \
		--js exports. js \
		--js_output_file jstemplate_compiled. js

	>examples/webenginewidgets/contentmanipulation/jquery. js cat debian/missing-sources/jquery-*. js
	yui-compressor --type js "examples/webenginewidgets/contentmanipulation/jquery. js" -o "examples/webenginewidgets/contentmanipulation/jquery. min. js"
	>src/3 rdparty/chromium/third_party/mocha/mocha. js tar xaf debian/missing-sources/mocha*. tar. gz --wildcards --to-stdout '*/mocha. js'


	set -ex; for fname in $(touch_files); do \
		mkdir -p $(CURDIR)/$$(dirname $${fname}); \
		touch $(CURDIR)/$${fname}; \
	done

override_dh_auto_build-arch:
	dh_auto_build -- -Onone

#we also need the resources. pak files, so we need the normal build.
override_dh_auto_build-indep: override_dh_auto_build-arch
	dh_auto_build -- docs

override_dh_auto_install-arch:
	dh_auto_install

	# Remove rpath from the offending binaries
	chrpath -d $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/qt 5/libexec/QtWebEngineProcess

	# Fix wrong path in pkgconfig files
	find $(CURDIR)/debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig -type f -name '*. pc' \
	-exec sed -i -e 's/$(DEB_HOST_MULTIARCH)\/$(DEB_HOST_MULTIARCH)/$(DEB_HOST_MULTIARCH)/g' {} \;

	# Remove libtool-like files
	rm -fv debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/*. la

override_dh_auto_install-indep: override_dh_auto_install-arch
	dh_auto_build -- INSTALL_ROOT=$(CURDIR)/debian/tmp install_docs

override_dh_link:
	dh_link --package=qtwebengine 5-examples \
		usr/share/javascript/jquery/jquery. min. js usr/lib/$(DEB_HOST_MULTIARCH)/qt 5/examples/webenginewidgets/contentmanipulation/jquery. min. js \
		usr/share/javascript/marked/marked. min. js usr/lib/$(DEB_HOST_MULTIARCH)/qt 5/examples/webenginewidgets/markdowneditor/resources/marked. js
	dh_link --package=qtwebengine 5-dev-tools \
		usr/lib/qt 5/bin/qwebengine_convert_dict usr/lib/$(DEB_HOST_MULTIARCH)/qt 5/bin/qwebengine_convert_dict

	dh_link --remaining-packages

override_dh_auto_test-arch:
	$(MAKE) install -Csrc/core INSTALL_ROOT=$(CURDIR)/test_root
	-QTWEBENGINEPROCESS_PATH=$(CURDIR)/libexec/QtWebEngineProcess xvfb-run -a \
		-s "-screen 0 1024 x 768 x 24 +extension RANDR +extension RENDER +extension GLX" \
		dh_auto_test --no-parallel -- -k \
		QML 2_IMPORT_PATH=$(CURDIR)/test_root/usr/lib/$(DEB_HOST_MULTIARCH)/qt 5/qml \
		LD_LIBRARY_PATH=$(CURDIR)/lib

override_dh_auto_test-indep:
	# Do not attempt to run anything to make build-indep work

可以看到,rules 文件里,故意删除了那些文件,那么为什么呢,后来在 README 文件中找到了答案

原因

xx/qtwebengine-opensource-src-5.15.2+dfsg/debian/missing-sources$ cat README                                                                                             
Missing source files                                                                                         
--------------------                                                                                         
QtWebEngine ships embeded minified javascript libraries.                                                     
The GPL requires you to provide the corresponding source code.                                               
For Debian all missing sources are bundled in this directory.                                                
They have been grabbed from the various upstream projects.                                                   
Last synchronization was made with QtWebEngine v5.9.2 at 2017-09-19.                                         
Files: examples/webenginewidgets/contentmanipulation/jquery.min.js                                           
Project: jQuery v1.3.2                                                                                       
License: Expat or GPL                                                                                        
Source: http://code.jquery.com/jquery-1.3.2.js                                                               
Files: examples/webenginewidgets/markdowneditor/resources/3rdparty/marked.min.js                             
Project: marked 0.3.6                                                                                        
License: Expat                                                                                               
Source: https://github.com/chjj/marked/archive/v0.3.6.tar.gz                                                                                          
Files: examples/webengine/recipebrowser/resources/pages/assets/3rdparty/marked.min.js                        
Project: marked 0.3.6                   
License: Expat  
Source: https://github.com/chjj/marked/archive/v0.3.6.tar.gz                         
Files: src/3rdparty/chromium/third_party/mocha/mocha.js          
Project: Mocha 2.5.3                    
License: MIT             
Source: https://github.com/mochajs/mocha/archive/v2.5.3.tar.gz   

简而言之,就是版权问题。

总结

以上便是在国产龙芯 CPU 架构国产 Linux 系统下编译 Qt 源码的整个过程。需要注意的就是,要使用已打好patch的源码包,即针对 LoongArch 架构适配之后的。

同时要注意,使用龙芯提供的源码包时,由于 debian 的 rules 文件将一些文件删除了,导致使用 Qt 官方编译方式会编译错误,所以需要自己补上缺失的文件。当然,如果使用 Debian dpkg-buildpackage -us -uc -tc -b的编译方式就不需要了。

https://www.cnblogs.com/tingtaishou/p/17387763.html
https://blog.csdn.net/2301_77077496/article/details/133315507
https://www.xssl.online/uos%e7%bc%96%e8%af%91qt-%e9%be%99%e8%8a%af/
https://loongson.github.io/LoongArch-Documentation/LoongArch-toolchain-conventions-CN.html#cc%E9%A2%84%E5%A4%84%E7%90%86%E5%99%A8%E5%86%85%E5%BB%BA%E5%AE%8F%E5%AE%9A%E4%B9%89


http://www.kler.cn/a/134288.html

相关文章:

  • MySQL重难点(一)索引
  • 前端开发中常用的包管理器(npm、yarn、pnpm、bower、parcel)
  • 记录学习react的一些内容
  • 【AI大模型】ELMo模型介绍:深度理解语言模型的嵌入艺术
  • LeetCode【0014】最长公共前缀
  • 动态规划 —— 子数组系列-最大子数组和
  • boomYouth
  • 2023.11.18html中如何使用input/button进行网页跳转
  • GIT无效的源路径/URL
  • SOME/IP 协议介绍(五)指南
  • 基于灰狼算法(GWO)优化的VMD参数(GWO-VMD)
  • 【Proteus仿真】【STM32单片机】防火防盗GSM智能家居设计
  • Dockerfile自定义镜像以及案例分析
  • C++二分查找算法:找到 Alice 和 Bob 可以相遇的建筑
  • Python PyQt 程序设置图标
  • JS-项目实战-鼠标悬浮变手势(鼠标放单价上生效)
  • 【Linux】安全审计-audit
  • SpringBoot静态资源配置
  • Linux socket编程(4):服务端fork之僵尸进程的处理
  • ClickHouse UDF 运行速度慢问题
  • docker容器内访问主机端口服务
  • Visual Studio Code 从英文界面切换中文
  • 鸿蒙:实现两个Page页面跳转
  • 多线程概述
  • RTMP协议和源码解析
  • MFC/QT 一些快要遗忘的细节: