aarch64-linux-gnu交叉编译Qt4.7.3
1.环境搭建:
1.安装automake、libtool 和主机上的 Qt ⼯具:
$ sudo apt-get install automake autoconf libtool m4
$ sudo apt-get install libX11-dev libXext-dev libXtst-dev libXrender-dev
$ sudo apt-get install libqt4-core libqt4-dev libqt4-webkit qt4-demos
2.搭建交叉编译环境:
环境搭建很简单,只要把交叉编译⼯具链解压后,在/etc/profile⽂件最后⼀⾏处添加环境变量,系统启动时会⾃动设置。
解压后进⼊⽬录,ls bin/可以看到aarch64-linux-gnu-gcc、aarch64-linux-gnu-g++等编译器。
复制代码
[~/qtArm64Toolchain/Ambarella_Linaro_Toolchain_2016.02_For_S5/linaro-aarch64-2016.02-gcc5.3 root@jz4775dev] [root@jz4775dev]# ls
aarch64-linux-gnu bin include lib lib64 libexec share
[~/qtArm64Toolchain/Ambarella_Linaro_Toolchain_2016.02_For_S5/linaro-aarch64-2016.02-gcc5.3 root@jz4775dev] [root@jz4775dev]# ls bin/
aarch64-linux-gnu-addr2line aarch64-linux-gnu-cpp aarch64-linux-gnu-gcc-ar aarch64-linux-gnu-gdb aarch64-linux-gnu-objcopy aarch64-linux-gnu-readelf
aarch64-linux-gnu-ar aarch64-linux-gnu-elfedit aarch64-linux-gnu-gcc-nm aarch64-linux-gnu-gprof aarch64-linux-gnu-objdump aarch64-linux-gnu-size
aarch64-linux-gnu-as aarch64-linux-gnu-g++ aarch64-linux-gnu-gcc-ranlib aarch64-linux-gnu-ld aarch64-linux-gnu-pkg-config aarch64-linux-gnu-strings
aarch64-linux-gnu-c++ aarch64-linux-gnu-gcc aarch64-linux-gnu-gcov aarch64-linux-gnu-ld.bfd aarch64-linux-gnu-pkg-config-real aarch64-linux-gnu-strip
aarch64-linux-gnu-c++filt aarch64-linux-gnu-gcc-5.3.1 aarch64-linux-gnu-gcov-tool aarch64-linux-gnu-nm aarch64-linux-gnu-ranlib 
复制代码
[root@jz4775dev]# vim /etc/profile
在最后⼀⾏添加:
export PATH=/root/qtArm64Toolchain/Ambarella_Linaro_Toolchain_2016.02_For_S5/linaro-aarch64-2016.02-
gcc5.3/bin:$PATH
2.编译安装Qt4.7.3
把qt-everywhere-opensource-src-4.7.拷贝到/opt ⽬录下,使⽤下⾯command解压:
tar -xvf qt-everywhere-opensource-src-4.7.
并在/opt⽬录下新建⽬录qt-4.7.3-arm64(qt-4.7.3-arm64是编译完成后的安装⽬录):
mkdir qt-4.7.3-arm64
然后进⼊qt-everywhere-opensource-src-4.7.3⽬录:
a.修改mkspecs/qws/linux-arm-gnueabi-g++/f⽂件如下:
1 #
2 # qmake configuration for building with arm-none-linux-gnueabi-g++
3 #
4
5 include(…/…/common/g++.conf)
6 include(…/…/f)
7 include(…/…/f)
8
9 # modifications to g++.conf
10 QMAKE_CC = aarch64-linux-gnu-gcc
11 QMAKE_CXX = aarch64-linux-gnu-g++
12 QMAKE_LINK = aarch64-linux-gnu-g++
13 QMAKE_LINK_SHLIB = aarch64-linux-gnu-g++
14
15 # modifications f
16 QMAKE_AR = aarch64-linux-gnu-ar cqs
17 QMAKE_OBJCOPY = aarch64-linux-gnu-objcopy
18 QMAKE_STRIP = aarch64-linux-gnu-strip
19
20 load(qt_config)
复制代码
b.执⾏configure⽣成Makefile⽂件,命令如下:
复制代码
./configure -opensource -prefix /opt/qt-4.7.3-arm64 -xplatform qws/linux-arm-gnueabi-g++ -embedded armv8 -release -webkit -no-cups -qt-zlib -qt-libjpeg -qt-libmng -qt-libpng -depths all -qt-gfx-linuxfb -qt-g
fx-transformed -no-gfx-qvfb -qt-gfx-vnc -qt-gfx-multiscreen -qt-kbd-tty -no-openssl -no-phonon -no-phonon-backend -no-nas-sound -no-exceptions -svg -no-qt3support -no-multimedia -no-xmlpatterns -no-pch -con
firm-license
复制代码
配置成功显⽰如下:
复制代码
NOTICE: Atomic operations are not yet supported for this
architecture.
Qt will use the 'generic' architecture instead, which uses a
single pthread_mutex_t to protect all atomic operations. This
implementation is the slow (but safe) fallback implementation
for architectures Qt does not yet support.
Qt is now configured for building. Just run ‘make’.
Once everything is built, you must run ‘make install’.
Qt will be installed into /opt/qt-4.7.3-arm64
To reconfigure, run ‘make confclean’ and ‘configure’.
复制代码
然后:
make
注意:
1. qt4.7.3 configure时要加上-embedded armv8参数,armv8是arm芯⽚的架构(arm9对应armv5,arm11对应armv6,cortex-
a8和cortex-a9对应armv7),不然会出现以下情况:
You have not explicitly asked to use pkg-config and are cross-compiling.
pkg-config will not be used to automatically query cflag/lib parameters for
dependencies
This is the Qt for Linux/X11 Open Source Edition.
You are licensed to use this software under the terms of
the Lesser GNU General Public License (LGPL) versions 2.1.
You are also licensed to use this software under the terms of
the GNU General Public License (GPL) versions 3.
You have already accepted the terms of the license.
Creating qmake. Please wait…
g++ -c -o option.o -m64 -pipe -DQMAKE_OPENSOURCE_EDITION -I. -Igenerators -Igenerators/unix -Igenerators/win32 -Igenerators/mac -Igenerators/symbian -I/opt/qt-everywhere-opensource-src-4.7.3/include -I/opt/qt-everywhere-opensource-src-4.7.3/include/QtCore -I/opt/qt-everywhere-opensource-src-4.7.3/src/corelib/global -I/opt/qt-everywhere-opensource-src-4.7.3/src/corelib/xml -I/opt/qt-everywhere-opensource-src-4.7.3/tools/shared -DQT_NO_PCRE -
DQT_BUILD_QMAKE -DQT_BOOTSTRAPPED -DQLIBRARYINFO_EPOCROOT -DQT_NO_TEXTCODEC -
DQT_NO_UNICODETABLES -DQT_NO_COMPONENT -DQT_NO_STL -DQT_NO_COMPRESS -I/
opt/qt-everywhere-opensource-src-4.7.3/mkspecs/linux-g+±64 -DHAVE_QCONFIG_CPP -DQT_NO_THREAD -DQT_NO_QOBJECT -
DQT_NO_GEOM_VARIANT option.cpp
g++ -o “/opt/qt-everywhere-opensource-src-4.7.3/bin/qmake” project.o property.o main.o makefile.o unixmake2.o unixmake.o mingw_make.o option.o winmakefile.o projectgenerator.o meta.o makefiledeps.o metamakefile.o xmloutput.o pbuilder_pbx.o borland_bmake.o msvc_vcproj.o msvc_vcxproj.o msvc_nmake.o msvc_objectmodel.o msbuild_objectmodel.o symmake.o initprojectdeploy_symbian.o symmake_abld.o symmake_sbsv2.o symbiancommon.o registry.o epocroot.o qtextcodec.o qutfcodec.o qstring.o qtextstream.o qiodevice.o qmalloc.o qglobal.o qbytearray.o qbytearraymatcher.o qdatastream.o qbuffer.o qlist.o qfile.o qfsfileengine_unix.o qfsfileengine_iterator_unix.o qfsfileengine.o
qfsfileengine_iterator.o qregexp.o qvector.o qbitarray.o qdir.o qdiriterator.o quuid.o qhash.o qfileinfo.o qdatetime.o qstringlist.o qabstractfileengine.o qtemporaryfile.o qmap.o qmetatype.o qsettings.o qlibraryinfo.o qvariant.o qvsnprintf.o qlocale.o qlinkedlist.o qurl.o qnumeric.o qcryptographichash.o qxmlstream.o qxmlutils.o -m64
Basic XLib functionality test failed!
You might need to modify the include and library search paths by editing
QMAKE_INCDIR_X11 and QMAKE_LIBDIR_X11 in /opt/qt-everywhere-opensource-src-4.7.3/mkspecs/qws/linux-arm-gnueabi-g++.
复制代码
2.执⾏make后可能会报错,不同的编译器版本出现的错误不⼀样,本⼈刚开始使⽤ ,aarch-linux-gnu 7.2.1版本编译器,出现如下错误:
复制代码
…/…/include/QtCore/…/…/src/corelib/tools/qmap.h: In instantiation of ‘T& QMap<Key, T>::operator[](const Key&) [with Key = int; T = inotify_event]’:
io/qfilesystemwatcher_inotify.cpp:364:33: required from here
…/…/include/QtCore/…/…/src/corelib/tools/qmap.h:531:45: error: value-initialization of incomplete type ‘char []’
node = node_create(d, update, akey, T());
^~~
复制代码
google了⼀波并没有到解决办法,个⼈感觉可能是qt代码太⽼的关系,好多东西到现在的Qt5.11都已经弃⽤,编译器太新导致出错,之前⽤aarch64-linux-gnu 7.2.1编译qt5.5.1并没有出现这个错误,所以决定换个编译器的版本尝试⼀下。改⽤aarch64-linux-gnu 5.3.1版本后,没有出现这个错误。
但是在后⾯编译时出现了新的错误,如下:
runtime/JSValue.h: In constructor ‘JSC::JSValue::JSValue(JSC::JSCell*)’:
runtime/JSValue.h:494:57: error: cast from ‘JSC::JSCell*’ to ‘int32_t {aka int}’ loses precision [-fpermissive]
u.asBits.payload = reinterpret_cast<int32_t>(ptr);
^
runtime/JSValue.h: In constructor ‘JSC::JSValue::JSValue(const JSC::JSCell*)’:
bootstrapped
runtime/JSValue.h:506:78: error: cast from ‘JSC::JSCell*’ to ‘int32_t {aka int}’ loses precision [-fpermissive]
u.asBits.payload = reinterpret_cast<int32_t>(const_cast<JSCell*>(ptr));
^
make[1]: *** [.obj/release-static-emb-armv8/JSBase.o] Error 1
make[1]: Leaving directory `/opt/qt-everywhere-opensource-src-4.7.3/src/3rdparty/webkit/JavaScriptCore’
make: *** [sub-javascriptcore-make_default-ordered] Error 2
复制代码
google了⼀下,原来是Qt4.7的⼀个Bug,国外⼤胸弟们也是⼀顿操作,然⽽并没有给出具体的解决办法,不知哪来的灵感,突然想到在64位arm上跑,会不会因为ptr ⼤于int32_t导致的出错,所以把494
和506⾏的int32_t改成int64_t,竟然编译通过了,但是编译完成后并没有⽣成webkit的动态库,很是⽆语。这个错误就是编译webkit第三⽅库的时候出现的,为什么编译通过后没有libQtWebKit.so.4.7.3呢!
既然没有⽣成webkit库,那就在configure后⾯加上参数 -webkit,指明编译这个库。configure后⽣成新的Makefile,make继续填坑。编译过程中⼜出现了这个错误。打开JSValue.h⽂件发现是修改过的int64_t,执⾏command:
[root@jz4775dev]# find ./ -name JSValue.h
./src/3rdparty/webkit/WebCore/ForwardingHeaders/runtime/JSValue.h
./src/3rdparty/webkit/JavaScriptCore/runtime/JSValue.h
./src/3rdparty/javascriptcore/JavaScriptCore/runtime/JSValue.h
原来有三个!
⼀个个来查看:
复制代码
[root@jz4775dev]# vim ./src/3rdparty/webkit/WebCore/ForwardingHeaders/runtime/JSValue.h
1 #ifndef WebCore_FWD_JSValue_h
2 #define WebCore_FWD_JSValue_h
3 #include <JavaScriptCore/JSValue.h>
4 #endif
复制代码
不是这个;
复制代码
[root@jz4775dev]# vim ./src/3rdparty/webkit/JavaScriptCore/runtime/JSValue.h
487
488 inline JSValue::JSValue(JSCell* ptr)
489 {
490 if (ptr)
491 u.asBits.tag = CellTag;
492 else
493 u.asBits.tag = EmptyValueTag;
494 u.asBits.payload = reinterpret_cast<int32_t>(ptr);
495 #if ENABLE(JSC_ZOMBIES)
496 ASSERT(!isZombie());
497 #endif
498 }
499
500 inline JSValue::JSValue(const JSCell* ptr)
501 {
502 if (ptr)
503 u.asBits.tag = CellTag;
504 else
505 u.asBits.tag = EmptyValueTag;
506 u.asBits.payload = reinterpret_cast<int32_t>(const_cast<JSCell*>(ptr));
507 #if ENABLE(JSC_ZOMBIES)
508 ASSERT(!isZombie());
509 #endif
510 }
复制代码
就是你了,把int32_t改成int64_t后继续编译,编译顺利完成。
这时在 “ls lib/” 查看:
复制代码
[root@jz4775dev]# ls lib/
fonts libQtCore.so libQtDeclarative.so.4.7 libQtNetwork.la libQtScript.la libQtScriptTools.so.4.7 libQtSvg.so libQtWebKit.la libQtXml.so
libphonon.la libQtCore.so.4 libQtDeclarative.so.4.7.3 libQtNetwork.prl libQtScript.prl libQtScriptTools.so.4.7.3 libQtSvg.so.4 libQtWebKit.prl libQtXml.so.4
libphonon.prl libQtCore.so.4.7 libQtGui.la libQtNetwork.so libQtScript.so libQtSql.la libQtSvg.so.4.7 libQtWebKit.so libQtXml.so.4.7
libpvrQWSWSEGL.prl libQtCore.so.4.7.3 libQtGui.prl libQtNetwork.so.4 libQtScript.so.4 libQtSql.prl libQtSvg.so.4.7.3 libQtWebKit.so.4 libQtXml.so.4.7.3
libQAxContainer.prl libQtDBus.la libQtGui.so libQtNetwork.so.4.7 libQtScript.so.4.7 libQtSql.so libQtTest.la
libQtWebKit.so.4.7 pkgconfig
libQAxServer.prl libQtDBus.prl libQtGui.so.4 libQtNetwork.so.4.7.3 libQtScript.so.4.7.3 libQtSql.so.4 libQtTest.prl libQtWebKit.so.4.7.3 README
libQt3Support.la libQtDeclarative.la libQtGui.so.4.7 libQtOpenGL.la libQtScriptTools.la libQtSql.so.4.7 libQtTest.so libQtXml.la libQt3Support.prl libQtDeclarative.prl libQtGui.so.4.7.3 libQtOpenGL.prl libQtScriptTools.prl libQtSql.so.4.7.3 libQtTest.so.4 libQtXmlPatterns.la
libQtCore.la libQtDeclarative.so libQtMultimedia.la libQtOpenVG.la libQtScriptTools.so libQtSvg.la libQtTest.so.4.7 libQtXmlPatterns.prl
libQtCore.prl libQtDeclarative.so.4 libQtMultimedia.prl libQtOpenVG.prl libQtScriptTools.so.4 libQtSvg.prl libQtTest.so.4.7.3 libQtXml.prl
复制代码
libQtWebKit.so.4.7.3 有了,嗯…美滋滋!
然后执⾏command:

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。