準(zhǔn)備好MIPS交叉編譯器
比如君正X2000的編譯器 mips-gcc720-glibc226
將其拷貝到/opt目錄下,然后設(shè)置好環(huán)境變量PATH。
在~/.bashrc中加上
export PATH=/opt/mips-gcc720-glibc226/bin:$PATH
預(yù)編譯tslib
tslib是一個(gè)用于觸摸事件的開源的庫(kù),可以從github上下載,我們用的是1.22版本。
Qt依賴它來(lái)實(shí)現(xiàn)觸屏事件
下載地址:https://github.com/libts/tslib
./autogen.sh
./configure --host=mips-linux-gnu --prefix=/opt/Qt5.9.0/tslib-1.22
make
make install
Ps:當(dāng)prefix指向/opt目錄時(shí)會(huì)在make install的時(shí)候報(bào)錯(cuò),可以參照https://blog.csdn.net/flfihpv259/article/details/51496959這篇博客解決,大概意思是在
./configure --host=mips-linux-gnu --prefix=/opt/Qt5.9.0/tslib-1.22 CC=/opt/mips-gcc720-glibc226/bin/mips-linux-gnu-gcc
加上加上編譯器的絕對(duì)路徑
預(yù)編譯sqlite3
下載地址:https://www.sqlite.org/download.html
下載sqlite-autoconf-3340100.tar.gz文件
./configure --host=mips-linux-gnu --prefix=/opt/Qt5.9.0/sqlite3
make
make install
注意:因?yàn)?opt目錄只有root權(quán)限能夠?qū)?,所以在make install 的時(shí)候會(huì)提示permission error,這時(shí)在make install前加sudo是沒用的,還是會(huì)報(bào)錯(cuò)誤。所以不如直接在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- # 改成我們實(shí)際使用的交叉編譯器
include(../common/linux_device_pre.conf)
QMAKE_CFLAGS = -EL -march=mips32r2
QMAKE_CXXFLAGS = $${QMAKE_CFLAGS}
QMAKE_LFLAGS = -EL
QT_QPA_DEFAULT_PLATFORM = linuxfb # xcb,因?yàn)闆]有GPU,所以默認(rèn)使用linuxfb
QMAKE_LIBS_EGL = -lEGL -lIMGegl -lusc
QMAKE_LIBS_OPENGL_ES2 = -lGLESv2 $${QMAKE_LIBS_EGL}
include(../common/linux_device_post.conf)
load(qt_config)
在根目錄下創(chuàng)建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
環(huán)境變量設(shè)置
#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
遇到的問(wèn)題
Q: 執(zhí)行./build.sh的時(shí)候報(bào)以下錯(cuò)誤
ERROR: Feature 'tslib' was enabled, but the pre-condition 'libs.tslib' failed.
A: 預(yù)編譯tslib的時(shí)候--host=mips-linux-gnu設(shè)置的編譯器不對(duì),要改成實(shí)際的交叉編譯器
Q: 編譯報(bào)錯(cuò)
../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: 編譯錯(cuò)誤
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: 據(jù)說(shuō)是Qt5.9.0的專屬錯(cuò)誤,產(chǎn)生錯(cuò)誤的原因是這是編譯帶有opengl的時(shí)候不會(huì)出問(wèn)題,但是如果沒有帶opengl,這個(gè)函數(shù)會(huì)在某個(gè)地方被調(diào)用,然后出錯(cuò)。
臨時(shí)解決辦法是修改qtlocation/src/location/maps/qgeotiledmapscene.cpp中第609行和第634行,把if(ogl)及后面那條語(yǔ)句注釋掉。
這個(gè)bug據(jù)說(shuō)在5.9.1修復(fù)了。
Q: 編譯錯(cuò)誤
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專屬錯(cuò)誤,提示qmapbox相關(guān)。這依舊是沒帶opengl出現(xiàn)的bug。臨時(shí)解決辦法:修改qtlocation/src/plugins/plugins.pro。
TEMPLATE = subdirs
qtHaveModule(positioning): SUBDIRS += position
#qtHaveModule(location): SUBDIRS += geoservices <---注釋掉這行
Q: 編譯出來(lái)的Qt SDK放到其他的電腦,并在Qt Creator里配置交叉編譯環(huán)境,配置的Qt Version一直有紅色感嘆號(hào)
A: 這是因?yàn)镼t SDK在編譯的時(shí)候把編譯環(huán)境的一些路徑也帶進(jìn)去了,導(dǎo)致在其他電腦上因?yàn)槁窂讲灰恢聢?bào)錯(cuò)。在網(wǎng)上找到一種解決方法,在qmake同級(jí)目錄下創(chuàng)建一個(gè)qt.conf文件,內(nèi)容如下:
[Paths]
Prefix = ..
但是我試了之后沒有效果。最后還是通過(guò)在編譯Qt的時(shí)候?qū)?prefix配置到/opt目錄,然后將編譯出來(lái)的SDK打包放到其他電腦的相同路徑下解決的問(wèn)題
Q: 運(yùn)行的時(shí)候報(bào)下面的錯(cuò)誤
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版本編譯出來(lái)沒有preloadable_libiconv.so庫(kù)
./configure --host=mips-linux-gnu --prefix=/opt/Qt5.9.0/libiconv
make
make install
編譯結(jié)果
/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拷貝到開發(fā)板的/opt/qtlib/libiconv/preloadable_libiconv.so,然后在環(huán)境變量中加上
export LD_PRELOAD=/opt/qtlib/libiconv/preloadable_libiconv.so
Qt5.12.7 交叉編譯遇到的問(wèn)題
Q: 編譯Qt5.12.7版本報(bào)錯(cuò)
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的時(shí)候加上宏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畫面需要旋轉(zhuǎn)90度
A: 參考http://www.manongjc.com/detail/15-stqwfnwutrfwvbx.html
https://www.programmersought.com/article/2758188732/
https://blog.csdn.net/du2005023029/article/details/101014114
https://blog.csdn.net/zmlovelx/article/details/83782966
修改qtbase\src\plugins\platforms\linuxfb目錄下的qlinuxfbscreen.h和qlinuxfbscreen.cpp這兩個(gè)文件
export QT_QPA_PLATFORM=linuxfb:fb=/dev/fb0:size=600x1024:mmSize=600x1024:offset=0x0:rotation=270
#TP也要旋轉(zhuǎn)
export QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS=/dev/input/event0:rotate=270:invertx:inverty