centos7 arm版本编译qt5.6.3详细说明
操作系统安装
系统镜像下载
安装镜像下载地址:https://archive.kernel.org/centos-vault/altarch/7.6.1810/isos/aarch64/
下载镜像文件:CentOS-7-aarch64-Everything-1810.iso
系统环境配置及调试
关闭防火墙
systemctl disable firewalld
systemctl stop firewalld
systemctl status firewalld
iptables -nvL #查看确认恢复初始,无任何网络拦截的配置
配置远程
修改sshd,允许root登录,然后重启sshd服务。
打开桌面共享(桌面设置中操作)。
配置在线源
默认在线源已经不维护了,访问不了,以下采用阿里源。
cd /etc/
cp -r yum.repos.d/ yum_repos_d
cd /etc/yum.repos.d/
wget http://mirrors.aliyun.com/repo/Centos-altarch-7.repo -O /etc/yum.repos.d/CentOS-Base.repo
rm -rf CentOS-fasttrack.repo
yum clean all
yum makecache
如果环境无法联网则可使用该镜像对应的离线源:
https://archive.kernel.org/centos-vault/altarch/7.6.1810/os/aarch64/Packages/
编译openssl
下载源码
openssl-1.0.2g.tar.gz
https://github.com/ope
nssl/openssl/tree/OpenSSL_1_0_2g
编译动态库
mkdir /root/BBin/openssl
# centos
./config --prefix=/root/BBin/openssl -shared
#麒麟server sp1
./config --prefix=/root/BBin/openssl --enable-shared
make
make install
编译完成后结果在/root/BBin/openssl下。
编译clamav
下载源码
git仓库下载0.103.6版本的clamav代码。
二次修改
下载的代码中,当clamscan在扫描的时候会打印一个提示,这种输出会影响我们对扫描结果的解析,所以源码中去除它:
Loading virus signature database, please wait... Done
修改代码后编译:
# 修改前
958 cbdata.filename = "Loading virus signature database, please wait... ";
959 cl_engine_set_clcb_sigload(engine, sigloadcallback, &cbdata);
1011 mprintf(cbdata.filename);
1012 mprintf("done\n");
# 修改后
958 cbdata.filename = "Loading virus signature database, please wait... ";
959 // cl_engine_set_clcb_sigload(engine, sigloadcallback, &cbdata);
1011 // mprintf(cbdata.filename);
1012 // mprintf("done\n");
编译依赖解决
根据过程中的编译报错,本次需要增补依赖。
yum install libtool-ltdl-devel # autogen.sh过程依赖
yum install gcc-c++ # clamav编译使用
yum install libxml2-devel.aarch64 # clamav编译使用
yum install libcurl-devel.aarch64
yum install pcre2-devel.aarch64
yum install json-c-devel.aarch64
yum install chrpath.aarch64 #编译后修改rpath使用
编译安装指定目录
编译过程更多细节可参考官网:https://docs.clamav.net/manual/Installing/Installing-from-source-Unix-old.html#redhat–centos–fedora
本次操作:
mkdir -p /root/BBin/clamav
./autogen.sh
# CFLAGS="-Wall -Wextra -ggdb -O0" CXXFLAGS="-Wall -Wextra -ggdb -O0" #如果编译debug版本,则添加此部分在configure前边
# 事后打包的时候再重置rpath,使用命令: chrpath -r \$ORIGIN/./:\$ORIGIN/../ ./clamscan
./configure --prefix=/root/BBin/clamav --with-pcre --with-openssl=/root/BBin/openssl
make && make install
报错解决记录1
[root@centos-pkg clamav-0.103.6]# ./autogen.sh
Generating autotools files in: /root/BCompile/clamav-0.103.6 ...
Use of uninitialized value in split at /usr/bin/autoreconf line 493, <GEN3> line 9.
libtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, `config'.
xxxxxxxx
libtoolize: copying file `m4/ltversion.m4'
libtoolize: copying file `m4/lt~obsolete.m4'
libtoolize: putting libltdl files in LT_CONFIG_LTDL_DIR, `libltdl'.
libtoolize: `COPYING.LIB' not found in `/usr/share/libtool/libltdl'
autoreconf: libtoolize failed with exit status: 1
Error: Failed to generate autojunk!
[root@centos-pkg clamav-0.103.6]#
解决方式:
yum install libtool-ltdl-devel
clamav使用验证
# 如下设置符号链接跟踪
root@test-pc:/opt/output/ClamAV# ./clamscan --no-summary --follow-dir-symlinks=2 --follow-file-symlinks=2 -d VirusDataBase/ /opt/output/ClamAV/
/opt/output/ClamAV/libssl.so.1.0.0: OK
/opt/output/ClamAV/libclammspack.so.0.1.0: OK
/opt/output/ClamAV/libcrypto.so.1.0.0: OK
/opt/output/ClamAV/libclamav.so.9.0.5: OK
/opt/output/ClamAV/libclamav.so.9.0.5: OK
/opt/output/ClamAV/libpcre2-8.so.0.5.0: OK
/opt/output/ClamAV/libclamunrar.so.9.0.5: OK
/opt/output/ClamAV/libclamunrar_iface.so.9.0.5: OK
/opt/output/ClamAV/libclamunrar_iface.so.9.0.5: OK
/opt/output/ClamAV/libclammspack.so.0.1.0: OK
/opt/output/ClamAV/libfreshclam.so.2.0.1: OK
/opt/output/ClamAV/libclamav.so.9.0.5: OK
/opt/output/ClamAV/libclamunrar.so.9.0.5: OK
/opt/output/ClamAV/libssl.so.1.0.0: OK
/opt/output/ClamAV/libclamunrar_iface.so.9.0.5: OK
/opt/output/ClamAV/libclamunrar.so.9.0.5: OK
/opt/output/ClamAV/clamscan: OK
/opt/output/ClamAV/libfreshclam.so.2.0.1: OK
/opt/output/ClamAV/libjson-c.so.2.0.1: OK
/opt/output/ClamAV/libclammspack.so.0.1.0: OK
/opt/output/ClamAV/libcrypto.so.1.0.0: OK
/opt/output/ClamAV/libpcre2-8.so.0.5.0: OK
/opt/output/ClamAV/libfreshclam.so.2.0.1: OK
/opt/output/ClamAV/libjson-c.so.2.0.1: OK
root@test-pc:/opt/output/ClamAV#
编译qt arm版本
必须注意
(1)使用的qt源码,不能从别的机器拷贝,否则编译中由于源码中存在残留的Makefile,残留的.o文件会导致新机器上出问题。为了避免出问题最好使用干净的源码。
(2)避免从拷贝或解压后的源码,会导致部分文件丢失权限, 从而在编译中报错,出现莫名其妙的问题。
综上,在线实时下载比较好。
下载源码 qt5.6.3
git clone git://code.qt.io/qt/qt5.git
cd qt5
git checkout v5.6.3
git submodule update --init --recursive
生成Makefile
注意:这里依赖前边编译的openssl,之前编译安装在/root/BBin/openssl/include目录。
mkdir -p /root/BBin/qt5.6.3
./configure -opensource -confirm-license -largefile -dbus-linked -openssl-linked -I /root/BBin/openssl/include -L /root/BBin/openssl/lib -no-rpath -make libs -make tools -fontconfig -qt-freetype -debug-and-release -qt-sql-sqlite -qt-zlib -qt-libpng -qt-libjpeg -dbus -openssl -qt-xcb -nomake tests -nomake examples -no-pch -prefix /root/BBin/qt5.6.3
注意:这一步如果出错,检查是否支持c++11,其次qtbase/qmake下是否存在以前其他机器的临时编译.o文件未清除,如果未清除会导致再次编译出异常。
qmake是qt编译的第一步,也是其他包括项目clean的关键工具。一般不会错,除非是代码不干净,干净的代码不会出错的。
其次,这一步会检查依赖,如果存在依赖缺失会打印出。这里一般qt用不到所有,不需要全部编译,比如configure阶段提示egl缺失,那么编译安装后就没有/plugins/egldeviceintegrations/这个插件相关内容,所以有时看到不同机器编译出的模块数量都不一致。这块根据,需要,保障最基本的存在即可,尝试着搞就行了。
如果存在需要的库没编译出则对应解决即可。如下在一个正常机器上的打印:
[root@localhost qt5]# ./configure -opensource -confirm-license -largefile -dbus-linked -openssl-linked -I /root/myb/openssl/include -L /root/myb/openssl/lib -no-rpath -make libs -make tools -fontconfig -qt-freetype -debug-and-release -qt-sql-sqlite -qt-zlib -qt-libpng -qt-libjpeg -dbus -openssl -qt-xcb -nomake tests -nomake examples -no-pch -no-neon -prefix /opt/qt5.6.3/
........
Done running configuration tests.
<srcbase> = /root/myb/qt5/qtbase
<outbase> = /root/myb/qt5/qtbase
Creating qmake...
.Done.
Running configuration tests (phase 2)...
checking for C++11... yes.
checking for C++14... no.
.........
checking for GStreamer 0.10... no.
Done running configuration tests.
Configure summary
Build type: linux-g++ (arm64, CPU features: none detected)
Platform notes:
- Also available for Linux: linux-clang linux-kcc linux-icc linux-cxx
Build options:
Configuration .......... accessibility accessibility-atspi-bridge audio-backend c++11 clock-gettime clock-monotonic compile_examples concurrent dbus enable_new_dtags evdev eventfd freetype full-config getaddrinfo getifaddrs harfbuzz iconv icu inotify ipv6ifname large-config largefile libudev linuxfb medium-config minimal-config mremap openssl pcre png posix_fallocate qpa qpa reduce_exports release shared small-config threadsafe-cloexec xcb xcb-glx xcb-plugin xcb-qt xcb-xlib xkbcommon-qt xlib xrender zlib
Build parts ............ libs tools
Using LTCG ............. no
.........
Support enabled for:
Accessibility .......... yes
ALSA ................... no
.........
zlib ................... yes (bundled copy)
Qt is now configured for building. Just run 'gmake'.
.........
测试g++是否支持C++11
g++ -std=c++11 -E - < /dev/null
如果无错误打印,则支持,如下案例。
[root@centos-pkg ~]# g++ -std=c++11 -E - < /dev/null
cc1: warning: command line option ‘-std=c++11’ is valid for C++/ObjC++ but not for C [enabled by default]
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 1 "<command-line>" 2
# 1 "<stdin>"
[root@centos-pkg ~]#
依赖安装
编译qt依赖的安装。
yum install libX11-devel.aarch64
yum install libXrender-devel.aarch64
yum install libxkbcommon-x11-devel.aarch64
yum install egl-utils.aarch64
yum install mesa-libGL-devel.aarch64
yum install mesa-libGLU-devel.aarch64
yum install freeglut-devel.aarch64
yum install libXext-devel libXfixes-devel libXi-devel libXrender-devel libxcb-devel libX11-devel libxkbcommon-x11-devel gstreamer* libgstreamer* zlib zlib-devel
yum install bison build-essential gperf flex ruby libasound2-dev libbz2-dev libcap-dev libcups2-dev libdrm-dev libegl1-mesa-dev libgcrypt11-dev libnss3-dev libpci-dev libpulse-dev libgudev1-devel.aarch64 libXtst-devel.aarch64 gyp ninja-build libglu1-mesa-dev libfontconfig1-dev libx11-xcb-dev libicu-dev
yum install libXi-devel.aarch64 libXinerama-devel.aarch64
yum install cups-devel.aarch64
编译安装
make
# 前边configure已经指定安装目录/root/BBin/qt5.6.3/
make install
报错解决记录
configure中qmake编译异常
configure过程中编译qmake异常。
[root@centos-pkg qt5]# ./configure -c++std c++11 -opensource -confirm-license -largefile -dbus-linked -openssl-linked -I /root/BBin/openssl/include -L /root/myb/openssl/lib -no-rpath -make libs -make tools -fontconfig -qt-freetype -debug-and-release -qt-sql-sqlite -qt-zlib -qt-libpng -qt-libjpeg -dbus -openssl -qt-xcb -nomake tests -nomake examples -no-pch -prefix /root/BBin/qt5.6.3
+ cd qtbase
+ /root/BCompile/qt5/qtbase/configure -top-level -c++std c++11 -opensource -confirm-license -largefile -dbus-linked -openssl-linked -I /root/BBin/openssl/include -L /root/myb/openssl/lib -no-rpath -make libs -make tools -fontconfig -qt-freetype -debug-and-release -qt-sql-sqlite -qt-zlib -qt-libpng -qt-libjpeg -dbus -openssl -qt-xcb -nomake tests -nomake examples -no-pch -prefix /root/BBin/qt5.6.3
This is the Qt Open Source Edition.
You are licensed to use this software under the terms of
the GNU Lesser General Public License (LGPL) version 2.1.
You are also licensed to use this software under the terms of
the GNU Lesser General Public License (LGPL) version 3.
You have already accepted the terms of the Open Source license.
WARNING: -debug-and-release is not supported outside of Mac OS X.
Qt can be built in release mode with separate debug information, so
-debug-and-release is not necessary anymore
Running configuration tests (phase 1)...
Done running configuration tests.
<srcbase> = /root/BCompile/qt5/qtbase
<outbase> = /root/BCompile/qt5/qtbase
Creating qmake...
.qsettings.o: In function `QList<QVariant>::node_destruct(QList<QVariant>::Node*, QList<QVariant>::Node*)':
/root/myb/qt5/qtbase/qmake/../include/QtCore/../../src/corelib/tools/qlist.h:484: undefined reference to `operator delete(void*, unsigned long)'
qsettings.o: In function `QList<QVariant>::node_copy(QList<QVariant>::Node*, QList<QVariant>::Node*, QList<QVariant>::Node*)':
/root/myb/qt5/qtbase/qmake/../include/QtCore/../../src/corelib/tools/qlist.h:458: undefined reference to `operator delete(void*, unsigned long)'
/root/myb/qt5/qtbase/qmake/../include/QtCore/../../src/corelib/tools/qlist.h:452: undefined reference to `operator delete(void*, unsigned long)'
qsettings.o: In function `QList<QVariant>::node_destruct(QList<QVariant>::Node*, QList<QVariant>::Node*)':
/root/myb/qt5/qtbase/qmake/../include/QtCore/../../src/corelib/tools/qlist.h:484: undefined reference to `operator delete(void*, unsigned long)'
qsettings.o: In function `QList<QVariant>::node_construct(QList<QVariant>::Node*, QVariant const&)':
/root/myb/qt5/qtbase/qmake/../include/QtCore/../../src/corelib/tools/qlist.h:425: undefined reference to `operator delete(void*, unsigned long)'
qsettings.o:/root/myb/qt5/qtbase/qmake/../include/QtCore/../../src/corelib/tools/qlist.h:425: more undefined references to `operator delete(void*, unsigned long)' follow
解决方式:
进入qtbase/qmake目录,删除以前缓存的.o文件,rm -rf *.o。之后重新编译。同时将qt源码中所有缓存的.o文件全部删除。
find ./ -name *.o | xargs -i rm -rf {}
configure中出现cannot read xxxxx.pri
缓存导致,qt源码是最新的则不会出现该问题,将qt源码中缓存的Makeifle全部删除。所有的Makefile都是临时生成,现存的都是以前缓存,缓存的在新机器会出问题(路径不对),必须删除重新建立。
find ./ -name Makefile | xargs -i rm -rf {}
make编译dec_neon.c编译报错
如下,在aarch64架构出现,百度说aarch64的gcc不支持,因为该架构默认启用,所以gcc不需要支持。去掉即可。
gcc -c -pipe -O2 -fvisibility=hidden -fno-exceptions -Wall -W -D_REENTRANT -fPIC -DQT_NO_MTDEV -DQT_NO_LIBUDEV -DQT_NO_TSLIB -DQT_NO_LIBINPUT -DQT_NO_EXCEPTIONS -D_LARGEFILE64_SOURCE -D_LARGEFILE_SOURCE -DQT_NO_DEBUG -DQT_PLUGIN -DQT_GUI_LIB -DQT_CORE_LIB -mfpu=neon -I. -I../../../3rdparty/libwebp -I../../../3rdparty/libwebp/src -I../../../3rdparty/libwebp/src/dec -I../../../3rdparty/libwebp/src/enc -I../../../3rdparty/libwebp/src/dsp -I../../../3rdparty/libwebp/src/mux -I../../../3rdparty/libwebp/src/utils -I../../../3rdparty/libwebp/src/webp -I/root/BCompile/qt5/qtbase/include -I/root/BCompile/qt5/qtbase/include/QtGui -I/root/BCompile/qt5/qtbase/include/QtCore -I.moc -I/root/BBin/openssl/include -I/root/BCompile/qt5/qtbase/mkspecs/linux-g++ ../../../3rdparty/libwebp/src/dsp/dec_neon.c -o .obj/dec_neon.o
gcc: error: unrecognized command line option ‘-mfpu=neon’
make[5]: *** [.obj/dec_neon.o] Error 1
make[5]: Leaving directory `/root/BCompile/qt5/qtimageformats/src/plugins/imageformats/webp'
make[4]: *** [sub-webp-make_first] Error 2
make[4]: Leaving directory `/root/BCompile/qt5/qtimageformats/src/plugins/imageformats'
make[3]: *** [sub-imageformats-make_first] Error 2
make[3]: Leaving directory `/root/BCompile/qt5/qtimageformats/src/plugins'
make[2]: *** [sub-plugins-make_first] Error 2
make[2]: Leaving directory `/root/BCompile/qt5/qtimageformats/src'
make[1]: *** [sub-src-make_first] Error 2
make[1]: Leaving directory `/root/BCompile/qt5/qtimageformats'
make: *** [module-qtimageformats-make_first] Error 2
解决方式
修改/root/BCompile/qt5/qtimageformats/src/plugins/imageformats/webp/Makefile 文件,将其中出现的-mfpu=neon全部删除,如下,
# 原始
gcc -c $(CFLAGS) -mfpu=neon $(INCPATH) ../../../3rdparty/libwebp/src/dsp/dec_neon.c -o .obj/dec_neon.o
# 修改后
gcc -c $(CFLAGS) $(INCPATH) ../../../3rdparty/libwebp/src/dsp/dec_neon.c -o .obj/dec_neon.o
make编译中gcc头文件导致报错
编译出现以下错误,这个是qt源码使用的gcc内部头文件和安装的gcc头文件接口类型不一致。
../../../3rdparty/libwebp/src/dsp/upsampling_neon.c: In function ‘UpsampleRgbLinePair’:
../../../3rdparty/libwebp/src/dsp/upsampling_neon.c:140:10: error: incompatible types when initializing type ‘int32x4_t’ using type ‘int32x2_t’
yl = vmlaq_lane_s32(yl, bl, cf32, 0); \
^
../../../3rdparty/libwebp/src/dsp/upsampling_neon.c:166:3: note: in expansion of macro ‘CONVERT8’
CONVERT8(FMT, XSTEP, len, top_y, uv, top_dst, cur_x) \
^
../../../3rdparty/libwebp/src/dsp/upsampling_neon.c:219:5: note: in expansion of macro ‘CONVERT2RGB_8’
CONVERT2RGB_8(FMT, XSTEP, top_y, bottom_y, r_uv, \
^
../../../3rdparty/libwebp/src/dsp/upsampling_neon.c:234:1: note: in expansion of macro ‘NEON_UPSAMPLE_FUNC’
NEON_UPSAMPLE_FUNC(UpsampleRgbLinePair, Rgb, 3)
^
../../../3rdparty/libwebp/src/dsp/upsampling_neon.c:141:10: error: incompatible types when initializing type ‘int32x4_t’ using type ‘int32x2_t’
yh = vmlaq_lane_s32(yh, bh, cf32, 0); \
^
../../../3rdparty/libwebp/src/dsp/upsampling_neon.c:166:3: note: in expansion of macro ‘CONVERT8’
解决方式
该问题通过升级gcc也可解决,但麻烦。这里通过分析出问题环境和正常环境对比,发现使用的gcc头文件 /usr/lib/gcc/aarch64-redhat-linux/4.8.2/include/arm_neon.h 文件存在声明差异导致。
以下是修改前后对比,如下仅修改9987行
9984 #define vmlaq_lane_s32(a, b, c, d) | #define vmlaq_lane_s32(a, b, c, d)
9985 __extension__ | __extension__
9986 ({ | ({
9987 /*int32x4_t myb modify*/int32x2_t c_ = (c); | int32x4_t c_ = (c);
调试说明
基于rpath查验外部库和QT插件加载是否正常
可采取以下手段
ldd查看依赖是否正常。
调试UI,开启插件调试开关:”export QT_DEBUG_PLUGINS=1“,手动运行可查看加载的插件信息。
LD_DEBUG=libs ./your_program 可以调试普通库加载的ld查找路径调试详情。
调试注意事项
系统的安全中心拦截。
qt环境编译总结
编译必须使用源码下载,拷贝的QT源码文件可能存在包括如:
(1)代码中含有中间编译结果;
(2)含有中间生成Makefile;
(3)复制过程导致代码格式异常(脚本换行符之类的系统差异异常);
(4)压缩解压过的文件存在执行权限丢失可能等。
编译必须编译所有,
只编译部分可能导致拿去用的时候发现程序运行OK,但呈现出的效果不符合预期,如界面组件文件缺失,窗口显示怪异等。所以执行configure中的检查缺失项尽可能的补齐依赖的安装,否则这里依赖缺失可能会引起后续make的时候部分组件直接不编译。