2023年6月26日发(作者:)
ubuntu下移植编译arm架构的QT利⽤QtCreator编译X86的Qt程序,直接点运⾏键就可编译运⾏程序,这是因为QtCreator帮我们配置了编译⼯具(qmake和gcc),但是要编译ARM版本的Qt程序,就需要移植ARM架构的QT库。⼀、下载交叉编译⼯具链下载arm -gcc的交叉编译⼯具链⼆、下载触摸屏库tslib1.切换到tslib⽬录: 安装交叉编译tslib必须的⼀些⼯具(可以先查看是否已安装,ubuntu16.04⾃带这些⼯具,可跳过) sudo apt-get install autoconf sudo apt-get install automake sudo apt-get install libtool2.利⽤脚本写编译过程在tslib⽂件夹下新建⽂件 内容如下:#!/bin/shmake clean && make distcleanecho "ac_cv_func_malloc_0_nonnull=yes" >C=/usr/local/arm/arm-2014.05/bin/arm-none-linux-gnueabi-gcc ./configure --host=arm-linux --prefix=/opt/tslib1.4 --cache-file=arm-l ake && make install3.运⾏./执⾏结束后,我们查看⼀下是否安装成功,执⾏命令:ls /opt/tslib1.4如果出现bin,etc,include,lib这4个⽬录,说明交叉编译并安装tslib成功。三、移植QT到ARM1、 要移植Qt必须要⽤到Qt的源码,在这⾥也是⽤Qt5的源码来移植。下载,选择⽂件下载。2、将下载好的移动⾄/opt⽬录下在/opt⽬录下解压:sudo tar -zxvf 然后进⼊解压后⽬录:cd qt-everywhere-opensource-src-xxx3、下⾯设置编译平台。编译器是通过xplatform参数指定的,xplatform后⾯跟的参数实际上就时qtbase/mkspec下的⽂件夹的名字,这⾥以linux-arm-gnueabi-g++为模板,拷贝这个⽂件夹,重命名为arm-linux,然后修改这个⽂件夹⾥的,修改后的内容如下:# qmake configuration for building with arm-linux-gnueabi-g++MAKEFILE_GENERATOR = UNIXCONFIG += incrementalQMAKE_INCREMENTAL_STYLE = sublibQT_QPA_DEFAULT_PLATFORM = linux #eglfsQMAKE_CFLAGS_RELEASE += -O2 -march=armv7-a // 指定平台QMAKE_CXXFLAGS_RELEASE += -O2 -march=armv7-ainclude(../common/)include(../common/)include(../common/g++-)/*以下是指定交叉编译⼯具链的具体路径(你也可以设置成环境变量,直接写arm-linux-gcc,这样就可以不⽤加上绝对路径,我这⾥因为linux下有多种版 本的⼯具链,所以加上绝对路径,具体写法要看你的linux情况)*/#modifications to g++.conf
QMAKE_CC = /usr/local/arm/gcc-4.6.2-glibc-2.13-linaro-multilib- 2011.12/fsl-linaro-toolchain/bin/arm-fsl-linux-gnueabi-gccQMAKE_CXX = /usr/local/arm/gcc-4.6.2-glibc-2.13-linaro-multilib- 2011.12/fsl-linaro-toolchain/bin/arm-fsl-linux-gnueabi-g++QMAKE_LINK = /usr/local/arm/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/arm-fsl-linux-gnueabi-g++QMAKE_LINK_SHLIB = /usr/local/arm/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/arm-fsl-linux-gnueabi-g++# modifications to AKE_AR = /usr/local/arm/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/arm-fsl-linux-gnueabi-ar cqsQMAKE_OBJCOPY = /usr/local/arm/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/arm-fsl-linux-gnueabi-objcopyQMAKE_NM = /usr/local/arm/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/arm-fsl-linux-gnueabi-nm -PQMAKE_STRIP = /usr/local/arm/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/arm-fsl-linux-gnueabi-stripload(qt_config)4、修改完成后返回顶层⽬录/opt/qt-everywhere-opensource-src-xxx。这时候要通过执⾏configure来⽣成Makefile⽂件了。我这⾥通过写⼀个脚本来⾃动⽣成Makefile⽂件,说⽩了就是把configure的参数写在脚本⽂件中。vim #!/bin/sh./configure -v -prefix /usr/local/Qt-5.5.0-arm //指定安装的位置-release -opensource -no-accessibility -make libs -xplatform linux-arm-gnueabi-g++ // 指定平台 linux-arm-gnueabi-g++ 就是上⾯我们编辑 的那个⽂件夹-optimized-qmake -pch -qt-sql-sqlite -qt-zlib -tslib -no-opengl -no-sse2 -no-openssl -no-nis -no-cups -no-glib -no-pkg-config -no-separate-debug-info -I/usr/local/arm/tslib/include -L/usr/local/arm/tslib/lib //指定tslib库,这是我linux中tslib库的路径configure下各个参数的含义 -prefix
-prefix
-debug :Compile and link Qt with debugging turned on.
-debug-and-release . Compile and link two versions of Qt, with and without
debugging turned on (Mac only).
-force-debug-info .. Create symbol files for release builds.
-developer-build ... Compile and link Qt with Qt developer options (including auto-tests exporting) -release 编译以及链接qt 但是关闭调试。⼀般的话 交叉编译qt的源码都选择这个选项。 -debug , 开启调试的接⼝ -debug-and-release 编译成上⾯连个版本。 -force-debug-info 创建字符⽂件为了记录版本 -developer-build 编译和链接qt ⽽且加⼊开发者选项(包含⾃⼰测试输出)。 -no-optimized-tools ... Do not build optimized host tools even in debug build. -optimized-tools ...... Build optimized host tools even in debug build.
-opensource ........ Compile and link the Open-Source Edition of Qt.
-commercial ........ Compile and link the Commercial Edition of Qt.
-confirm-license ... Automatically acknowledge the license (use with
either -opensource or -commercial)
-c++std
前⾯两个是 是否要建⽴优化主⼯具当调试的时候,⼀般会选择 -no-optimized-tools -opensource 编译和链接开源QT版本,⼀般的话我们都是使⽤的开源的QT版本。 -commercial 编译和链接商业QT版本。 -confirm-license ⾃动确认是否是开源还是商业的。 -c++std <> 编译QT 是使⽤的什么版本的c++ ,默认为最⾼版本 -shared: Create and use shared Qt libraries.
-static: Create and use static Qt libraries.
-no-largefile ...... Disables large file support.
-largefile ......... Enables Qt to access files larger than 4 GB.
-no-accessibility .. Do not compile Accessibility support.
Disabling accessibility is not recommended, as it will break QStyle and may break other internal parts of Qt.
With this switch you create a source incompatible version of Qt, which is unsupported.
-accessibility ..... Compile Accessibility support.
-no-sql-
-qt-sql-
none are turned on.
第⼀个⽐较容易理解: 是编译成动态库还是静态库,⼀般的话我们编译的都是动态库,这样的话软件的⼤⼩不会那么⼤, 选择的是 -shared第⼆个是是否允许⼤⽂件⽀持, 这个我还没没有试过。 ⼀般选择的都是默认的,默认是 -largefile第三个是易接近⽀持, 因为不同版本的qt都做了⼀些相关的改动, ⼀般的话都选择默认, 这样的话可以提⾼软件的可移植性。 -accessibility第四个是SQL 驱动模块的指定。我这⾥是没有这个模块的驱动的,所以我不去指定这个选项⼀般 -plugin-sql-
Possible values for
[ db2 ibase mysql oci odbc psql sqlite sqlite2 tds ]
-system-sqlite: Use sqlite from the operating system.
-no-qml-debug : Do not build the in-process QML debugging support.
-qml-debug ......... Build the QML debugging support.
-platform target ... The operating system and compiler you are building
on (default detected from host system).
See the README file for a list of supported
operating systems and compilers.
前⾯两个还是关于sql 的。⼀个允许sql作为⼀个插件在运⾏的时候,⼀个使⽤系统的sqlite
下⾯那个是指定是否编译QML 调试⽀持, ⼀般我选择的是:-no-qml-debug 第三块是选择⽬标平台:默认是选择本机的操作系统, 阅读顶层⽬录的readme 可以知道⽀持哪些操作系统。 -qtnamespace
-qtlibinfix
-testcocoon ........ Instrument Qt with the TestCocoon code coverage tool.
-gcov .............. Instrument Qt with the GCov code coverage tool.
-D
-I
-L
第⼀个是qt命名空间的, ⼀般不修改。第⼆个是对qt库的重命名,加⼀些后缀。⼀般我们也⽤不到。第三第四个是关于testcocoon 和 GCov的⼯具,⼀般我也不会去指定后⾯三个第⼀个是 在预处理的时候加⼀个前缀,第⼆个是添加⼀个额外的头⽂件⽬录,第三个是添加⼀个额外的库⽬录 -pkg-config ........ Use pkg-config to detect include and library paths. By default, configure determines whether to use pkg-config or not with some heuristics such as checking the environment variables.-no-pkg-config ..... Disable use of pkg-config.
-force-pkg-config .. Force usage of pkg-config (skips pkg-config usability
detection heuristic).
-help, -h .......... Display this information.
第⼀个是指定是否⽀持pkg-config 它回去寻找属于你的头⽂件以及库,后⾯还有⼀个强迫使⽤,意思就是必须使⽤。第⼆个是打印帮助。Third Party Libraries:-qt-zlib … Use the zlib bundled with Qt.-system-zlib … Use zlib from the operating /zlib-no-mtdev … Do not compile mtdev support.-mtdev … Enable mtdev support.-no-journald … Do not send logging output to journald.-journald … Send logging output to journald.-no-syslog … Do not send logging output to syslog.-syslog … Send logging output to syslog.-no-gif … Do not compile GIF reading support.-no-libpng … Do not compile PNG support.-qt-libpng … Use the libpng bundled with Qt.-system-libpng … Use libpng from the operating /pub/png-no-libjpeg … Do not compile JPEG support.-qt-libjpeg … Use the libjpeg bundled with Qt.-system-libjpeg … Use libjpeg from the operating 第⼀个是zlib 库, 默认是系统的zlib , 但是我们要选 -qt-zlib ,不要问我为什么, 因为我现在是在做移植,系统的是X86架构的,板⼦不⼀样。第⼆个是mtdev ⽀持, 是触摸屏多点控制协议的⽀持。如果你的触摸屏要多点控制,那就加上。 -medev.第三个是输⼊⽇志⽀持,有必要的话可以加上。 -syslog , ⼀般的话我选择默认。第四个是指定没有gif 阅读功能 , 我都不需要这个功能, 所以我会加上 -no-gif。第五个是指定是否⽀持PNG 这个我⼀般也是会加上 -no-libpng , 或者是-qt-libpng。第六个是指定jpeg 库⽀持, 和上⾯那个同理,-no-libjpeg或者是 -qt-libjpeg。-no-freetype … Do not compile in Freetype2 support.-qt-freetype … Use the libfreetype bundled with Qt.-system-freetype… Use the libfreetype provided by the system (enabled if -fontconfig is active).See -no-harfbuzz … Do not compile HarfBuzz-NG support.-qt-harfbuzz … Use HarfBuzz-NG bundled with Qt to do text can still be disabled by settingthe QT_HARFBUZZ environment variable to “old”.-system-harfbuzz … Use HarfBuzz-NG from the operating systemto do text shaping. It can still be disabledby setting the QT_HARFBUZZ environment variable to “old”.See -no-openssl … Do not compile support for OpenSSL.-openssl … Enable run-time OpenSSL support.-openssl-linked … Enabled linked OpenSSL support.-no-libproxy … Do not compile support for libproxy-libproxy … Use libproxy from the operating system.第⼀个是 freetype2 的编译⽀持。 ⼀般我会选择-no-freetype 或者是-qt-freetype . 原则是只要是有关操作系统,最好不要有system 字眼。第⼆个是有关字体的。⼀般我会选择-qt-harfbuzz.第三个是 openssl ,⼀般我会选择-no-openssl 。第四个是 proxy , 最好不要搭上本机操作系统 , -no-libproxy-qt-pcre … Use the PCRE library bundled with Qt.-system-pcre … Use the PCRE library from the operating system.-qt-xcb … Use xcb- libraries bundled with Qt.( will still be used from operating system).-system-xcb … Use xcb- libraries from the operating system.-xkb-config-root … Set default XKB config root. This option is used only together with -qt-xkbcommon-x11.-qt-xkbcommon-x11 … Use the xkbcommon library bundled with Qt in combination with xcb.-system-xkbcommon-x11 Use the xkbcommon library from the operating system in combination with xcb.-no-xkbcommon-evdev . Do not use X-less xkbcommon when compiling libinput support.-xkbcommon-evdev … Use X-less xkbcommon when compiling libinput 是⼀个c语⾔编写的正则表达式库,这⾥的话可以不指定。xcb 这⾥的话我指定的是qt-xcbxkb 这⾥的话我没去搭理他,-no-xinput2 … Do not compile XInput2 support.-xinput2 … Compile XInput2 support.-no-xcb-xlib… Do not compile Xcb-Xlib support.-xcb-xlib… Compile Xcb-Xlib support.-no-glib … Do not compile Glib support.-glib … Compile Glib support.-no-pulseaudio … Do not compile PulseAudio support.-pulseaudio … Compile PulseAudio support.-no-alsa … Do not compile ALSA support.-alsa … Compile ALSA support.-no-gtkstyle … Do not compile GTK theme support.-gtkstyle … Compile GTK theme 2 是关乎多点触摸的, 现在我还没有⽤到,所以我忽略了他。xcb-xlib 我也没有去管他。glib 我是直接给了 -no-glibpulseaudio 这是关于声⾳系统的。我给了是默认alsa 这是⾳频⼦系统的⽀持。 也是默认就⾏了。gtkstype GTK 主题⽀持,这个还是算了吧,我只求能移植成功,功能不要太炫。Additional options:-make
-nomake
-skip
-no-compile-examples ... Install only the sources of examples.
-no-gui ............ Don't build the Qt GUI module and dependencies.
-gui … Build the Qt GUI module and dependencies.-no-widgets … Don’t build the Qt Widgets module and dependencies.-widgets … Build the Qt Widgets module and dependencies.第⼀个是让你选择要不要编译某些另外的模块, ⽐如说libs , tools , examples .我现在是把所有的加上,因为移植进去了就可以直接⽤examples⾥⾯的程序执⾏看⼀下是否移植成功。第⼆项是 gui ⽀持,我直接加上吧。第三个 widgets 也是差不多,也是直接上了。-R … Add an explicit runtime library path to the Qtlibraries.-l … Add an explicit library.-no-rpath .......... Do not use the library install path as a runtime
library path. On Apple platforms, this implies using
absolute install names (based in -libdir) for dynamic
libraries and frameworks.
-rpath … Link Qt libraries and executables using the libraryinstall path as a runtime library path. Equivalentto -R install_libpath-continue … Continue as far as possible if an error occurs.-verbose, -v … Print verbose information about each step of theconfigure process.-silent … Reduce the build output so that warnings and errorscan be seen more easily.第⼀项是添加⼀个库在Qt程序执⾏时,这个我不管我选默认。第⼆项是添加⼀个库我⼀般给这个rpath 给默认值。-continue 是指定如果出现某个错误指令继续的命令。-v 是指打印详细的信息关于每个配置程序-silent 是指定减少输出的信息,这样的话查找错误就更容易。-no-cups … Do not compile CUPS support.-cups … Compile CUPS es cups/cups.h and .2.-no-iconv … Do not compile support for iconv(3).-iconv … Compile support for iconv(3).-no-evdev … Do not compile support for evdev.-evdev … Compile support for evdev.-no-tslib … Do not compile support for tslib.-tslib … Compile support for tslib.-no-icu … Do not compile support for ICU libraries.-icu … Compile support for ICU libraries.-cups 是打印管理的⼀个⽀持, ⼀般的话选择默认就好。-iconv 这是⽂本编码转化功能,这个⽹上有些教程说应该去掉这个功能 所以选择 -no-iconv, ⽬前还没有试验。 -evdev 这个选择默认就⾏。-tslib 这个是触摸屏矫正的⼀个功能。这个还是要加上。-icu 这个选项还是选择默认。-no-linuxfb … Do not compile Linux Framebuffer support.-linuxfb … Compile Linux Framebuffer support.-no-opengl … Do not support OpenGL.-opengl … Enable OpenGL supportWith no parameter, this will attempt to auto-detectOpenGL ES 2.0 and higher, or regular desktop es2 for to override auto-detection.这连个选项, 使⽤linuxfb 的⽀持已经忽略opengl-linux -no-opengl5、写好了脚本后就更改好权限并执⾏chmod 777 ./6、执⾏完毕之后,就会在⽬录下发现Makefile⽂件。7、执⾏make,这是⼀个漫长的过长,估计要等⼀个半钟左右。8、执⾏make install,最后Qt5移植完成了,在安装⽬录下/usr/local/Qt-xxx-arm/bin,就会发现ARM版本的qmake,如果是编译ARM版本的Qt程序,就需要⽤到这个qmake。四、配置交叉编译⼯具链1、⾸先打开QtCreator->Tools->Options->Build &Run -> Compieirs如下图所⽰2、点击add->gcc,添加交叉编译⼯具链,在Name中输⼊名字(随便起⼀个吧),Complier path中输⼊你的交叉编译⼯具链在linux上的绝对路径。3、Apply 、 OK。五、配置qmake1、⾸先打开QtCreator->Tools->Options->Build &Run -> Qt Version如下图所⽰点击add,在version name输⼊名字(随便写⼀个),在 qmake location 中填⼊ARM版本qmake的绝对路径。其中ARM版本的qmake,需要通过移植Qt才能产⽣。六、配置Kits⼯具1、⾸先打开QtCreator->Tools->Options->Build &Run -> Kits如下图所⽰2、点击Add、在Complier处选择刚才配置好的交叉编译⼯具链的名字,在Qt Version处选择刚才配置好的qmake的名字。3、Apply 、OK。七、开始编译ARM版本的Qt程序1、⾸先点击clean all 来清除项⽬的编译信息。2、点击 build all 来编译项⽬。⼋、在⽬标板上运⾏1、将编译好的QT拷贝到⽬标板上,这⾥放到/opt⽬录下。2、指定QT的运⾏平台,这⾥使⽤linuxfb,QT有⼏种运⾏平台,在官⽹上有,这⾥使⽤linuxfb,新建⼀个⽂件,写下如下内容: export QTDIR=/opt/QT5.5 export QT_QPA_FONTDIR=QTDIR/lib/fonts export QT_QPA_PLATFORM_PLUGIN_PATH=$QTDIR/plugins/ export LD_LIBRARY_PATH=$QTDIR/lib:$LD_LIBRARY_PATH export QT_QPA_PLATFORM=linuxfb:fb=/dev/fb0:size=800x600:mmSize=800x600:offset=0x0:tty=/dev/tty1如果不指定QT_QPA_FONTDIRQT就会到/QT5.5的路径下去找字体,结果就找不到了。如果不指定QT_QPA_PLATFORM_PLUGIN_PATH,应⽤程序启动的时候就会提⽰找不到linuxfb,linuxfb是QT的⼀个插件,可以在/opt/QT5.5/plugins/platforms/⽂件夹下看到⼀个。LD_LIBRARY_PATH是指定库的路径,这个就不说了,最熟悉的东西了。QT_QPA_PLATFORM是指定平台,fb指定framebuffer的设备地址,具体的参数在官⽹上有说明参见上⾯给出的链接。然后运⾏source 添加这些环境变量,⾄此,界⾯就可以显⽰出来了。
发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1687753256a39504.html
评论列表(0条)