Ubuntu 平台交叉编译 Qt SQLite 动态库
本文简要记录一下如何在 Ubuntu 平台交叉编译 MIPS 平台的 Qt SQLite 动态库。
交叉编译工具⌗
首先,我们需要安装交叉编译工具。我们使用 mips-gcc520-glibc222.tgz
二进制包进行安装。
$ tar xf mips-gcc520-glibc222.tgz -C /opt
$ ls -al /opt/mips-gcc520-glibc222/
total 44
drwxr-xr-x 8 root root 4096 Mar 16 2018 .
drwxr-xr-x 3 root root 4096 May 16 11:31 ..
drwxr-xr-x 2 root root 4096 Jun 6 2019 bin
drwxr-xr-x 3 root root 4096 Mar 16 2018 i686-pc-linux-gnu
drwxr-xr-x 3 root root 4096 Mar 16 2018 lib
drwxr-xr-x 3 root root 4096 Mar 16 2018 libexec
drwxr-xr-x 7 root root 4096 Mar 16 2018 mips-linux-gnu
drwxr-xr-x 5 root root 4096 Mar 16 2018 share
-rw-r--r-- 1 root root 2613 Mar 16 2018 .SOURCE
-rw-r--r-- 1 root root 3345 Mar 16 2018 .UPDATE
-rw-r--r-- 1 root root 43 Mar 16 2018 VERSION
Qt 源码编译安装⌗
接着从 Qt 官网下载源码,此处我选择使用 qt-everywhere-src-5.12.3。
$ tar xf qt-everywhere-src-5.12.3.tar.xz
$ ls -l qt-everywhere-src-5.12.3
total 352
-rw-rw-r-- 1 japin japin 2845 Apr 11 2019 _clang-format
drwxrwxr-x 5 japin japin 4096 Apr 11 2019 coin
-rwxrwxr-x 1 japin japin 1935 Apr 11 2019 configure
-rw-rw-r-- 1 japin japin 1980 Apr 11 2019 configure.bat
-rw-rw-r-- 1 japin japin 94 Apr 11 2019 configure.json
drwxrwxr-x 9 japin japin 4096 Apr 11 2019 gnuwin32
-rw-rw-r-- 1 japin japin 22961 Apr 11 2019 LICENSE.FDL
-rw-rw-r-- 1 japin japin 15351 Apr 11 2019 LICENSE.GPLv2
-rw-rw-r-- 1 japin japin 35641 Apr 11 2019 LICENSE.GPLv3
-rw-rw-r-- 1 japin japin 26828 Apr 11 2019 LICENSE.LGPLv21
-rw-rw-r-- 1 japin japin 8174 Apr 11 2019 LICENSE.LGPLv3
-rw-rw-r-- 1 japin japin 46903 Apr 11 2019 LICENSE.QT-LICENSE-AGREEMENT-4.0
drwxrwxr-x 10 japin japin 4096 Apr 12 2019 qt3d
drwxrwxr-x 8 japin japin 4096 Apr 12 2019 qtactiveqt
drwxrwxr-x 7 japin japin 4096 Apr 12 2019 qtandroidextras
drwxrwxr-x 14 japin japin 4096 May 17 10:15 qtbase
drwxrwxr-x 7 japin japin 4096 Apr 12 2019 qtcanvas3d
drwxrwxr-x 8 japin japin 4096 Apr 12 2019 qtcharts
drwxrwxr-x 8 japin japin 4096 Apr 12 2019 qtconnectivity
drwxrwxr-x 7 japin japin 4096 Apr 12 2019 qtdatavis3d
drwxrwxr-x 10 japin japin 4096 Apr 12 2019 qtdeclarative
drwxrwxr-x 6 japin japin 4096 Apr 12 2019 qtdoc
drwxrwxr-x 8 japin japin 4096 Apr 12 2019 qtgamepad
drwxrwxr-x 6 japin japin 4096 Apr 12 2019 qtgraphicaleffects
drwxrwxr-x 6 japin japin 4096 Apr 12 2019 qtimageformats
drwxrwxr-x 8 japin japin 4096 Apr 12 2019 qtlocation
drwxrwxr-x 7 japin japin 4096 Apr 12 2019 qtmacextras
drwxrwxr-x 8 japin japin 4096 Apr 12 2019 qtmultimedia
drwxrwxr-x 7 japin japin 4096 Apr 12 2019 qtnetworkauth
-rw-rw-r-- 1 japin japin 2962 Apr 11 2019 qt.pro
drwxrwxr-x 7 japin japin 4096 Apr 12 2019 qtpurchasing
drwxrwxr-x 6 japin japin 4096 Apr 12 2019 qtquickcontrols
drwxrwxr-x 7 japin japin 4096 Apr 12 2019 qtquickcontrols2
drwxrwxr-x 9 japin japin 4096 Apr 12 2019 qtremoteobjects
drwxrwxr-x 8 japin japin 4096 Apr 12 2019 qtscript
drwxrwxr-x 9 japin japin 4096 Apr 12 2019 qtscxml
drwxrwxr-x 8 japin japin 4096 Apr 12 2019 qtsensors
drwxrwxr-x 8 japin japin 4096 Apr 12 2019 qtserialbus
drwxrwxr-x 8 japin japin 4096 Apr 12 2019 qtserialport
drwxrwxr-x 8 japin japin 4096 Apr 12 2019 qtspeech
drwxrwxr-x 8 japin japin 4096 Apr 12 2019 qtsvg
drwxrwxr-x 7 japin japin 4096 Apr 12 2019 qttools
drwxrwxr-x 3 japin japin 4096 Apr 12 2019 qttranslations
drwxrwxr-x 7 japin japin 4096 Apr 12 2019 qtvirtualkeyboard
drwxrwxr-x 8 japin japin 4096 Apr 12 2019 qtwayland
drwxrwxr-x 7 japin japin 4096 Apr 12 2019 qtwebchannel
drwxrwxr-x 10 japin japin 4096 Apr 12 2019 qtwebengine
drwxrwxr-x 5 japin japin 4096 Apr 12 2019 qtwebglplugin
drwxrwxr-x 7 japin japin 4096 Apr 12 2019 qtwebsockets
drwxrwxr-x 7 japin japin 4096 Apr 12 2019 qtwebview
drwxrwxr-x 7 japin japin 4096 Apr 12 2019 qtwinextras
drwxrwxr-x 6 japin japin 4096 Apr 12 2019 qtx11extras
drwxrwxr-x 8 japin japin 4096 Apr 12 2019 qtxmlpatterns
-rw-rw-r-- 1 japin japin 3842 Apr 11 2019 README
随后,我们便可以对其进行编译了,我们先尝试在 x86-64 平台编译。
$ mkdir x86-64-build && cd x86-64-build
$ ../configure \
-prefix $PWD/qt-x86/ \
-mp \
-release \
-shared \
-confirm-license \
-opensource \
-c++std c++11 \
-qt-sqlite \
-no-opengl \
-nomake examples \
-nomake tools \
-nomake tests \
-no-sse2 \
-no-cups \
-no-iconv \
-no-openssl
make -j4 -s
make install
整个编译过程比较久,可以先去喝杯咖啡再来。
$ find . -name libqsqlite.so
./qtbase/plugins/sqldrivers/libqsqlite.so
$ file $(find . -name libqsqlite.so)
./qtbase/plugins/sqldrivers/libqsqlite.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=f06c0992b7ffe4d438df0e065511564b1ef238a7, not stripped
交叉编译⌗
MIPS 的交叉编译工具已经安装了,并且在 x86-64 平台也成功编译了 qt-sqlite
,现在我们尝试编译 MIPS 平台的 qt-sqlite
。我们需要在 qtbase/mkspecs/
目录下添加上 MIPS 平台相关的信息。
$ mkdir qtbase/mkspecs/linux-mips-gnu-g++ && cd qtbase/mkspecs/linux-mips-gnu-g++
$ cat <<EOF > qmake.conf
#
# qmake configuration for building with arm-linux-gnueabi-g++
#
MAKEFILE_GENERATOR = UNIX
CONFIG += incremental
QMAKE_INCREMENTAL_STYLE = sublib
include(../common/linux.conf)
include(../common/gcc-base-unix.conf)
include(../common/g++-unix.conf)
# modifications to g++.conf
QMAKE_CC = mips-linux-gnu-gcc
QMAKE_CXX = mips-linux-gnu-g++
QMAKE_LINK = mips-linux-gnu-g++
QMAKE_LINK_SHLIB = mips-linux-gnu-g++
# modifications to linux.conf
QMAKE_AR = mips-linux-gnu-ar cqs
QMAKE_OBJCOPY = mips-linux-gnu-objcopy
QMAKE_NM = mips-linux-gnu-nm -P
QMAKE_STRIP = mips-linux-gnu-strip
load(qt_config)
EOF
$ cat <<EOF > qplatformdefs.h
/****************************************************************************
**
** Copyright (C) 2016 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/
**
** This file is part of the qmake spec of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms
** and conditions see https://www.qt.io/terms-conditions. For further
** information use the contact form at https://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 3 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL3 included in the
** packaging of this file. Please review the following information to
** ensure the GNU Lesser General Public License version 3 requirements
** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 2.0 or (at your option) the GNU General
** Public license version 3 or any later version approved by the KDE Free
** Qt Foundation. The licenses are as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
** included in the packaging of this file. Please review the following
** information to ensure the GNU General Public License requirements will
** be met: https://www.gnu.org/licenses/gpl-2.0.html and
** https://www.gnu.org/licenses/gpl-3.0.html.
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "../linux-g++/qplatformdefs.h"
EOF
$ cd -
qmake.conf
指定了使用的编译工具,qplatformdefs.h
则给出了需要依赖的头文件。
现在,我们便可以编译 MIPS 平台的 qt-sqlite
了。
$ mkdir mips-build
$ export PATH=/opt/mips-gcc520-glibc222/bin:$PATH
$ ../configure \
-prefix $PWD/qt-mips/ \
-mp \
-release \
-shared \
-xplatform linux-mips-gnu-g++ \
-confirm-license \
-opensource \
-c++std c++11 \
-qt-sqlite \
-no-opengl \
-nomake examples \
-nomake tools \
-nomake tests \
-no-sse2 \
-no-cups \
-no-iconv \
-no-openssl
make -j4 -s
make install
编译完成之后可以看到如下信息。
$ find . -name libqsqlite.so
./qtbase/plugins/sqldrivers/libqsqlite.so
$ file $(find . -name libqsqlite.so)
./qtbase/plugins/sqldrivers/libqsqlite.so: ELF 32-bit LSB shared object, MIPS, MIPS32 rel2 version 1 (SYSV), dynamically linked, not stripped
后记⌗
由于我们并不是使用标准的 SQLite,因此我们将其替换,在我们的 SQLite 中使用了额外的动态库。为了能顺利通过编译,我们需要执行动态库的路径,我当前的做法是通过修改 qtbase/src/3rdparty/sqlite.pri
来实现的(暂时没有找到更好的解决方案),即在该文件中加入如下内容:
LIBS += -L/path/to/lib/dir -lmylib
Read other posts