本文主参考:http://zero.lichee.pro/%E5%BA%94%E7%94%A8/QT_index.html
环境 Ubuntu16 64位
arm-linux-gnueabihf version 6.3.1 20170109 (Linaro GCC 6.3-2017.02)
(根据参考链接编译嵌入式版本Qt4.8.7时遇到诸多问题,特此记录)
1.交叉编译并安装
sudo apt-get install libtool automake autogen autoconf libsysfs-dev
git clone https://github.com/kergoth/tslib.git
cd tslib
echo "ac_cv_func_malloc_0_nonnull=yes" > tmp.cache
./autogen.sh
./configure --host=arm-linux-gnueabihf --cache-file=tmp.cache --prefix=/opt/tslib CC=arm-linux-gnueabihf-gcc
make
sudo make install
完成后会在Ubuntu系统/opt目录下出现tslib文件夹,将此文件夹拷贝置嵌入式系统相同目录下,配置嵌入式系统环境变量 vi /etc/profile,根据自己系统添加如下内容:
#export TSLIB_ROOT=/opt/tslib
#export TSLIB_TSDEVICE=/dev/input/event1
#export TSLIB_CALIBFILE=/etc/pointercal
#export TSLIB_CONFFILE=$TSLIB_ROOT/etc/ts.conf
#export TSLIB_PLUGINDIR=$TSLIB_ROOT/lib/ts
#export TSLIB_FBDEVICE=/dev/fb0
#export TSLIB_CONSOLEDEVICE=none
#export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$TSLIB_ROOT/lib
/dev/fb0对应显示设备。添加保存后 source /etc/profile 使能环境变量,运行/opt/tslib/bin/ts_test 测试是否成功。/opt/tslib/bin/ts_calibrate为触摸校准程序。
2.交叉编译QT4.8.7
下载 qt-everywhere-opensource-src-4.8.7.tar.gz并解压,进入文件夹内修改文件 vim mkspecs/qws/linux-arm-gnueabi-g++/qmake.conf,修改后内容如下:
#
# qmake configuration for building with arm-none-linux-gnueabi-g++
# include(../../common/linux.conf)
include(../../common/gcc-base-unix.conf)
include(../../common/g++-unix.conf)
include(../../common/qws.conf) # modifications to g++.conf
QMAKE_CC = arm-linux-gnueabihf-gcc -lts
QMAKE_CXX = arm-linux-gnueabihf-g++ -lts
QMAKE_LINK = arm-linux-gnueabihf-g++ -lts
QMAKE_LINK_SHLIB = arm-linux-gnueabihf-g++ -lts # modifications to linux.conf
QMAKE_AR = arm-linux-gnueabihf-ar cqs
QMAKE_OBJCOPY = arm-linux-gnueabihf-objcopy
QMAKE_STRIP = arm-linux-gnueabihf-strip load(qt_config) QMAKE_INCDIR += /opt/tslib/include /opt/sqlite3/include
QMAKE_LIBDIR += /opt/tslib/lib /opt/sqlite3/lib
QMAKE_CXXFLAGS = $$QMAKE_CFLAGS -std=gnu++
修改完成后执行如下命令配置Qt编译环境:
./configure -verbose -opensource -confirm-license -release -shared -embedded arm -xplatform qws/linux-arm-gnueabi-g++ -depths ,,, -fast -optimized-qmake -pch -qt-sql-sqlite -qt-libjpeg -qt-zlib -qt-libpng -qt-freetype -little-endian -host-little-endian -no-opengl -no-openssl -nomake examples -make docs -qt-mouse-tslib -I/opt/tslib/include -L/opt/tslib/lib -prefix /opt/qt-4.8.-arm
等待配置完成后,执行:
make -j8
make install
make和install都顺利的话会出现/opt/qt-4.8.7-arm。同样将其拷贝置嵌入式系统的相同目录下并配置环境变量vi /etc/profile,根据自己系统添加如下内容:
export TSLIB_CONSOLEDEVICE=none
export TSLIB_FBDEVICE=/dev/fb0
export TSLIB_TSDEVICE=/dev/input/event1
export TSLIB_CONFFILE=/opt/tslib/etc/ts.conf
export TSLIB_PLUGINDIR=/opt/tslib/lib/ts
export TSLIB_CALIBFILE=/etc/pointercal
export LD_LIBRARY_PATH=/lib:/usr/lib:/opt/tslib/lib:/opt/qt-4.8.-arm/lib
export PATH=/bin:/sbin:/usr/bin/:/usr/sbin:/opt/tslib/bin
export QT_QPA_PLATFORM_PLUGIN_PATH=/opt/qt-4.8.-arm/plugins
export QT_QPA_PLATFORM=linuxfb:tty=/dev/fb0
export QT_QPA_FONTDIR=/opt/qt-4.8.-arm/lib/fonts
export QT_QPA_GENERIC_PLUGINS=tslib:$TSLIB_TSDEVICE
export QWS_MOUSE_PROTO=Tslib:/dev/input/event1
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opti/tslib/lib:/opt/qt-4.8.-arm/lib:/usr/lib/arm-linux-gnueabihf/lib
(以上环境变量包含上文中已经配置过的tslib环境变量)
3.使用Qt Creator编译项目并在嵌入式设备中运行
自行安装Qt Creator,新建项目:
编译后将生成文件拷贝置嵌入式系统中, /root/qt_test -qws 运行(记住需要加 -qws)。
如果运行出错:
QLock::QLock: Cannot create semaphore /tmp/qtembedded-/QtEmbedded- 'd' (, Function not implemented)
Cannot get display lock
请重新编译内核,在配置中勾选General setup ---> System V IPC
然后运行即可。