首先从官网下载QT的嵌入式版,注意官网上的嵌入式版和linux版都是199M,其实他们在官网上的位置不一样,
Qt libraries 4.7.0 for embedded Linux (199 MB)
http://get.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.7.0.tar.gz
Qt libraries 4.7.0 for Linux/X11(199 MB)
http://get.qt.nokia.com/qt/source/qt-everywhere-opensource-src-4.7.0.tar.gz
其实下载下来是一样(看他们的下载路径都是一样的)的,。下载下来的文件名为: qt-everywhere-opensource-src-4.7.0.tar.gz
解压
tar zxvf qt-everywhere-opensource-src-4.7.0.tar.gz
把解压后的文件再复制两份(一共三份),分别取名为pc; x86; arm;然后开始分别编译:
1.编译PC,
cd pc
这一步可能出错:1
此完整出错信息是在./configure阶段
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 /home/zhu/Qt/qt-x11-opensource-src-4.5.2/mkspecs/linux-g++
进config.test /x11/xlib 执行make命令,看出错信息
g++ -Wl,-O1 -o xlib xlib.o -L/usr/X11R6/lib -lXext -lX11 -lm
/usr/bin/ld: cannot find -lXext
可以看到,g++在/usr/X11R6/lib下,找不到libXext.so
其原因就在于需要安装libX11的开发包,根据自己的系统特点,安装 libX11-dev libXext-dev libXtst-dev
可能出错2:
/usr/bin/ld: cannot find -lXrender
说明还少一个包:安装 libxrender-dev
sudo apt-get install cutecom
sudo apt-get install autoconf automake libtool
截至到现在,最后一次make没有出错,但有不错warning,不管它
sudo make install
2. 编译嵌入式x86版:
进入x86目录,设置其以QVFB作为显示输出
# sudo ./configure -prefix /usr/local/Trolltech/QtEmbedded-4.7.0 -embedded x86 -qt-gfx-qvfb -qt-kbd-qvfb -qt-mouse-qvfb
# sudo make
# sudo make install
编译安装PC 版中的 qvfb:
进入pc/tools/qvfb/目录
#make
#make install
3.编译arm版:
先安装tslib1.4
下载:http://download.csdn.net/source/2803217
获得包后,交叉编译tslib
export PREFIX=/usr/local/tslib #设置目标位置
./autogen.sh #用于生成configure脚本
echo "ac_cv_func_malloc_0_nonnull=yes" >arm-linux.cache
#产生一个cache文件arm-linux.cache,欺骗configure,
CC=arm-linux-gcc ./configure --host=arm-linux --prefix=$PREFIX --cache-file=arm-linux.cache
make
make install
交叉成功后在目标位置产生/bin、/etc、/include、/lib 4个文件夹
(编译的时候注意arm-linux-gcc在当前shell下是不是有效,没有的话必需事先export进去)
qt for arm:
cd arm
在下面建立一个脚本:
#vim myconfig.sh
#!/bin/bash
./configure -prefix /usr/local/Trolltech/QtEmbedded-4.7.0-arm -opensource -confirm-license -release -shared -embedded arm -xplatform qws/linux-arm-g++ -depths 16,18,24 -fast -optimized-qmake -qt-sql-sqlite -qt-libjpeg -qt-zlib -qt-libpng -qt-freetype -little-endian -host-little-endian -no-qt3support -no-libtiff -no-libmng -no-opengl -no-mmx -no-sse -no-sse2 -no-3dnow -no-openssl -no-webkit -no-qvfb -no-phonon -no-nis -no-opengl -no-cups -no-glib -no-xcursor -no-xfixes -no-xrandr -no-xrender -no-separate-debug-info -nomake examples -nomake tools -nomake docs -D__ARM_ARCH_5TEJ__ -qt-mouse-tslib -I/usr/local/gtkdfb/include -L/usr/local/gtkdfb/lib
根据移植需要选择相应的内容,执行configure
(-qt-mouse-tslib下面是刚刚编译的tslib1.4的目录,-D__ARM_ARCH_5TEJ__是为了解决下面提到的问题 这里没有)
#source myconfig.sh
编译
#make
#make install
可能出错1:
{standard input}: Assembler messages:
{standard input}:778: Error: register or shift expression expected -- `orr r3,r2,lsl#16'
{standard input}:789: Error: register or shift expression expected -- `orr r2,r3,lsl#16'
{standard input}:7748: Error: register or shift expression expected -- `orr r3,r0,lsl#16'
{standard input}:7761: Error: register or shift expression expected -- `orr r1,r0,lsl#16'
make[1]: *** [.obj/release-shared-emb-arm/qfontengine_ft.o] Error 1
make[1]: Leaving directory `/home/lijian/QT/build/3.4.1gcc/qt-embedded-4.6.2/src/gui'
make: *** [sub-gui-make_default-ordered] Error 2
方案:
To fix this issue patch /src/3rdparty/freetype/include/freetype/config/ftconfig.h Line 330.
"orr %0, %2, lsl #16/n/t" /* %0 |= %2 << 16 */
to "orr %0, %0, %2, lsl #16/n/t" /* %0 |= %2 << 16 */
PS: 都说是交叉编译器版本问题,用4.5.1就好了... 没试过...
可能出错2:
In file included from ./config.h:26,
from ../JavaScriptCore/pcre/pcre_compile.cpp:44:
../JavaScriptCore/wtf/Platform.h:338:6: #error "Not supported ARM architecture"
make[1]: *** [obj/release/pcre_compile.o] Error 1
make[1]: Leaving directory `/usr/local/qte4.6-arm/src/3rdparty/webkit/WebCore'
make: *** [sub-webkit-make_default-ordered] Error 2
方案:
在参数上加 -D__ARM_ARCH_5TEJ__ 或者 -D__ARM_ARCH_4T
或者修改src/3rdparty/webkit/WebCore/Makefile,在cflags中加入-D__ARM_ARCH_4T__ 修改src/script/Makefile,同上
可能出错3:
warning: libts-0.0.so.0, needed by , not found (try using -rpath or -rpath-link)
undefined reference to `ts_read_raw'
undefined reference to `ts_open'
undefined reference to `ts_fd'
undefined reference to `ts_config'
undefined reference to `ts_close'
undefined reference to `ts_read'
collect2: ld returned 1 exit status
解决办法:
修改qt-everywhere-opensource-src-4.6.0/mkspecs/qws/linux-arm-g++/qmake.conf 文件(添加lts参数):
QMAKE_CC = arm-linux-gcc -lts
QMAKE_CXX = arm-linux-g++ -lts
QMAKE_LINK = arm-linux-g++ -lts
QMAKE_LINK_SHLIB = arm-linux-g++ -lts
还有个错误是加了-pch 参数引起的,具体错误内容忘了。
另外一定要在编译之前确认arm-linux-gcc等环境在当前shell下是否有效,如果出错最好拿一份新的源码再去编译,之前就是因为没有换而浪费了很多时间。
安装完成后,在 /usr/local/Trolltech 目录中有三个文件夹:Qt-4.7.0、QtEmbedded-4.7.0、QtEmbedded-4.7.0-arm。