天天看点

mips-mti-gnu-linux,[MIPS]Qt5.9.0交叉编译

准备好MIPS交叉编译器

比如君正X2000的编译器 mips-gcc720-glibc226

将其拷贝到/opt目录下,然后设置好环境变量PATH。

在~/.bashrc中加上

export PATH=/opt/mips-gcc720-glibc226/bin:$PATH

预编译tslib

tslib是一个用于触摸事件的开源的库,可以从github上下载,我们用的是1.22版本。

Qt依赖它来实现触屏事件

./autogen.sh

./configure --host=mips-linux-gnu --prefix=/opt/Qt5.9.0/tslib-1.22

make

make install

./configure --host=mips-linux-gnu --prefix=/opt/Qt5.9.0/tslib-1.22 CC=/opt/mips-gcc720-glibc226/bin/mips-linux-gnu-gcc

加上加上编译器的绝对路径

预编译sqlite3

下载sqlite-autoconf-3340100.tar.gz文件

./configure --host=mips-linux-gnu --prefix=/opt/Qt5.9.0/sqlite3

make

make install

注意:因为/opt目录只有root权限能够写,所以在make install 的时候会提示permission error,这时在make install前加sudo是没用的,还是会报错误。所以不如直接在root用户下编译

交叉编译Qt

此处我们采用的是Qt5.9.0版本,解压之后修改qtbase/mkspecs/devices/linux-mipsel-ci20-g++/qmake.conf

#

# qmake configuration for building with mips-mti-linux-gnu-g++

# build for CI20 targets X11

#

CROSS_COMPILE = mips-linux-gnu- # 改成我们实际使用的交叉编译器

include(../common/linux_device_pre.conf)

QMAKE_CFLAGS = -EL -march=mips32r2

QMAKE_CXXFLAGS = $${QMAKE_CFLAGS}

QMAKE_LFLAGS = -EL

QT_QPA_DEFAULT_PLATFORM = linuxfb # xcb,因为没有GPU,所以默认使用linuxfb

QMAKE_LIBS_EGL = -lEGL -lIMGegl -lusc

QMAKE_LIBS_OPENGL_ES2 = -lGLESv2 $${QMAKE_LIBS_EGL}

include(../common/linux_device_post.conf)

load(qt_config)

在根目录下创建build.sh文件

./configure -prefix /opt/Qt5.9.0/Qt5 \

-opensource \

-release \

-shared \

-pch \

-sqlite \

-I/opt/Qt5.9.0/sqlite3/include \

-L/opt/Qt5.9.0/sqlite3/lib \

-qt-zlib \

-qt-libjpeg \

-qt-libpng \

-qt-freetype \

-no-openssl \

-gui \

-widgets \

-nomake examples \

-nomake tests \

-nomake tools \

-optimized-qmake \

-no-opengl \

-no-cups \

-no-xkb \

-no-sm\

-no-separate-debug-info \

-xplatform devices/linux-mipsel-ci20-g++ \

-linuxfb \

-confirm-license \

-tslib \

-I/opt/Qt5.9.0/tslib-1.22/include \

-L/opt/Qt5.9.0/tslib-1.22/lib \

-recheck-all

chmod a+x build.sh

./build.sh

make -j24

make install

环境变量设置

#tslib

export TSLIB_ROOT=/opt/qtlib/tslib-1.22

export TSLIB_CONSOLEDEVICE=none

export TSLIB_FBDEVICE=/dev/fb0

export TSLIB_TSDEVICE=/dev/input/event0

export TSLIB_CALIBFILE=/etc/pointercal

export TSLIB_CONFFILE=$TSLIB_ROOT/etc/ts.conf

export TSLIB_PLUGINDIR=$TSLIB_ROOT/lib/ts

export TSLIB_TSEVENTTYPE=INPUT

#sqlite3

export SQLITE_ROOT=/opt/qtlib/sqlite3

#QT

export QTDIR=/opt/qtlib/qt5.12.7

export QT_QPA_PLATFORM_PLUGIN_PATH=$QTDIR/plugins

export QT_QPA_PLATFORM=linuxfb:fb=/dev/fb0:size=600x1024:mmSize=600x1024:offset=0x0:rotation=270

export QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS=/dev/input/event0:rotate=270:invertx:inverty

export QT_QPA_FONTDIR=/opt/qtlib/fonts

export QML2_IMPORT_PATH=$QTDIR/qml

export TSDEVICE=/dev/input/event0

#system

export LD_LIBRARY_PATH=$QTDIR/lib:$TSLIB_ROOT/lib:$SQLITE_ROOT/lib:$LD_LIBRARY_PATH

export LD_PRELOAD=/opt/qtlib/libiconv/preloadable_libiconv.so

export PATH=$TSLIB_ROOT/bin:$PATH

export XDG_RUNTIME_DIR=/usr/lib/

export RUNLEVEL=3

#debug

#export QT_DEBUG_PLUGINS=1

遇到的问题

Q: 执行./build.sh的时候报以下错误

ERROR: Feature 'tslib' was enabled, but the pre-condition 'libs.tslib' failed.

A: 预编译tslib的时候--host=mips-linux-gnu设置的编译器不对,要改成实际的交叉编译器

Q: 编译报错

../3rdparty/masm/assembler/MIPSAssembler.h: In member function 'void JSC::MIPSAssembler::vmov(JSC::MIPSAssembler::RegisterID, JSC::MIPSAssembler::RegisterID, JSC::MIPSAssembler::FPRegisterID)':

../3rdparty/masm/assembler/MIPSAssembler.h:696:9: error: 'mfhc1' was not declared in this scope

mfhc1(rd2, rn);

^~~~~

../3rdparty/masm/assembler/MIPSAssembler.h:696:9: note: suggested alternative: 'mthc1'

mfhc1(rd2, rn);

^~~~~

mthc1

Makefile:23325: recipe for target '.obj/qv4unop.o' failed

make[3]: *** [.obj/qv4unop.o] Error 1

Makefile:22966: recipe for target '.obj/qv4binop.o' failed

make[3]: *** [.obj/qv4binop.o] Error 1

Makefile:21955: recipe for target '.obj/qv4assembler.o' failed

make[3]: *** [.obj/qv4assembler.o] Error 1

Makefile:22607: recipe for target '.obj/qv4isel_masm.o' failed

make[3]: *** [.obj/qv4isel_masm.o] Error 1

Makefile:26773: recipe for target '.obj/qv4engine.o' failed

make[3]: *** [.obj/qv4engine.o] Error 1

make[3]: Leaving directory '/data/Qt/qt-everywhere-opensource-src-5.9.0/qtdeclarative/src/qml'

Makefile:52: recipe for target 'sub-qml-make_first-ordered' failed

make[2]: *** [sub-qml-make_first-ordered] Error 2

make[2]: Leaving directory '/data/Qt/qt-everywhere-opensource-src-5.9.0/qtdeclarative/src'

Makefile:48: recipe for target 'sub-src-make_first' failed

make[1]: *** [sub-src-make_first] Error 2

make[1]: Leaving directory '/data/Qt/qt-everywhere-opensource-src-5.9.0/qtdeclarative'

Makefile:360: recipe for target 'module-qtdeclarative-make_first' failed

make: *** [module-qtdeclarative-make_first] Error 2

A: 参考https://bugreports.qt.io/browse/QTBUG-89706 , 修改qtbase/src/corelib/global/qprocessordetection.h

# if defined(_MIPS_ARCH_MIPS32) || defined(__mips32) || (defined(__mips) && __mips - 0 >= 32)

# define Q_PROCESSOR_MIPS_32

# endif

改成

# if defined(_MIPS_ARCH_MIPS32) || defined(__mips32)

# define Q_PROCESSOR_MIPS_32

# endif

Q: 编译错误

qgeotiledmapscene.cpp:(.text+0x4bf4): undefined reference to `QSGDefaultImageNode::setAnisotropyLevel(QSGTexture::AnisotropyLevel)'

qgeotiledmapscene.cpp:(.text+0x5884): undefined reference to `QSGDefaultImageNode::setAnisotropyLevel(QSGTexture::AnisotropyLevel)'

qgeotiledmapscene.cpp:(.text+0x4bec): undefined reference to `QSGDefaultImageNode::setAnisotropyLevel(QSGTexture::AnisotropyLevel)'

qgeotiledmapscene.cpp:(.text+0x587c): undefined reference to `QSGDefaultImageNode::setAnisotropyLevel(QSGTexture::AnisotropyLevel)'

A: 据说是Qt5.9.0的专属错误,产生错误的原因是这是编译带有opengl的时候不会出问题,但是如果没有带opengl,这个函数会在某个地方被调用,然后出错。

临时解决办法是修改qtlocation/src/location/maps/qgeotiledmapscene.cpp中第609行和第634行,把if(ogl)及后面那条语句注释掉。

这个bug据说在5.9.1修复了。

Q: 编译错误

Makefile:201: recipe for target 'sub-------3rdparty-mapbox-gl-native-make_first' failed

make[4]: *** [sub-------3rdparty-mapbox-gl-native-make_first] Error 2

make[4]: Leaving directory '/data/Qt/qt-everywhere-opensource-src-5.9.0/qtlocation/src/plugins/geoservices'

Makefile:71: recipe for target 'sub-geoservices-make_first' failed

make[3]: *** [sub-geoservices-make_first] Error 2

make[3]: Leaving directory '/data/Qt/qt-everywhere-opensource-src-5.9.0/qtlocation/src/plugins'

Makefile:204: recipe for target 'sub-plugins-make_first' failed

make[2]: *** [sub-plugins-make_first] Error 2

make[2]: Leaving directory '/data/Qt/qt-everywhere-opensource-src-5.9.0/qtlocation/src'

Makefile:47: recipe for target 'sub-src-make_first' failed

make[1]: *** [sub-src-make_first] Error 2

make[1]: Leaving directory '/data/Qt/qt-everywhere-opensource-src-5.9.0/qtlocation'

Makefile:891: recipe for target 'module-qtlocation-make_first' failed

make: *** [module-qtlocation-make_first] Error 2

A: Qt5.9.0专属错误,提示qmapbox相关。这依旧是没带opengl出现的bug。临时解决办法:修改qtlocation/src/plugins/plugins.pro。

TEMPLATE = subdirs

qtHaveModule(positioning): SUBDIRS += position

#qtHaveModule(location): SUBDIRS += geoservices

Q: 编译出来的Qt SDK放到其他的电脑,并在Qt Creator里配置交叉编译环境,配置的Qt Version一直有红色感叹号

A: 这是因为Qt SDK在编译的时候把编译环境的一些路径也带进去了,导致在其他电脑上因为路径不一致报错。在网上找到一种解决方法,在qmake同级目录下创建一个qt.conf文件,内容如下:

[Paths]

Prefix = ..

但是我试了之后没有效果。最后还是通过在编译Qt的时候将-prefix配置到/opt目录,然后将编译出来的SDK打包放到其他电脑的相同路径下解决的问题

Q: 运行的时候报下面的错误

QIconvCodec::convertToUnicode: using Latin-1 for conversion, iconv_open failed

QIconvCodec::convertFromUnicode: using Latin-1 for conversion, iconv_open failed

A: 从 http://ftp.gnu.org/gnu/libiconv/libiconv-1.15.tar.gz下载源代码编译,注意不要下载1.16版本,1.16版本编译出来没有preloadable_libiconv.so库

./configure --host=mips-linux-gnu --prefix=/opt/Qt5.9.0/libiconv

make

make install

编译结果

/opt/Qt5.9.0/libiconv/lib/

├── charset.alias

├── libcharset.a

├── libcharset.la

├── libcharset.so -> libcharset.so.1.0.0

├── libcharset.so.1 -> libcharset.so.1.0.0

├── libcharset.so.1.0.0

├── libiconv.la

├── libiconv.so -> libiconv.so.2.6.0

├── libiconv.so.2 -> libiconv.so.2.6.0

├── libiconv.so.2.6.0

└── preloadable_libiconv.so

将preloadable_libiconv.so拷贝到开发板的/opt/qtlib/libiconv/preloadable_libiconv.so,然后在环境变量中加上

export LD_PRELOAD=/opt/qtlib/libiconv/preloadable_libiconv.so

Qt5.12.7 交叉编译遇到的问题

Q: 编译Qt5.12.7版本报错

qsql_sqlite.cpp:(.text+0x2154): undefined reference to `sqlite3_column_table_name16'

qsql_sqlite.cpp:(.text+0x217c): undefined reference to `sqlite3_column_table_name16'

qsql_sqlite.cpp:(.text+0x2184): undefined reference to `sqlite3_column_table_name16'

A: 在编译sqlite3的时候加上宏SQLITE_ENABLE_COLUMN_METADATA

./configure --host=mips-linux-gnu --prefix=/opt/Qt5.12.7/sqlite3 CFLAGS=-DSQLITE_ENABLE_COLUMN_METADATA

Q: Qt5.12.7 linuxfb画面需要旋转90度

export QT_QPA_PLATFORM=linuxfb:fb=/dev/fb0:size=600x1024:mmSize=600x1024:offset=0x0:rotation=270

#TP也要旋转

export QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS=/dev/input/event0:rotate=270:invertx:inverty