Ubuntu16.04下Qt交叉编译开发环境搭建

来源:互联网 发布:淘宝网无线话筒 编辑:程序博客网 时间:2024/04/30 06:14

一、环境及软件包介绍:

(一)系统环境

ubuntu16.04 64位

(二)软件包  (以下所有软件包下载地址:http://pan.baidu.com/s/1o8OwEFo)

1、arm-linux-gcc.tar.gz   

我提供的包是arm-linux-gcc4.4.3版本,arm-linux-gcc是编译arm开发板上程序用的一种gcc。

2、qt-everywhere-opensource-src-4.8.5.tar.gz  

  这个包是QT4.8.5的源码包,everywhere意思就是可以编译出适合各种平台的版本。

3、qt-embedded-linux-opensource-src-4.5.0.tar.bz2

这是qt4.5.0用于编译嵌入式的源码包。

4、tslib-1.4.tar.gz

tslib一种触摸屏校准驱动,用触摸屏操作的板子都需要这个,需要用触摸屏操作的软件自然也需要这里面的库。

5、qt-creator-opensource-linux-x86_64-4.1.0.run

qt-creator是一款经常与qt配合使用的IDE,这是目前的最新版。


二、目录约定及准备工作:

(一)目录约定:
交叉编译器路径:/usr/local/arm-linux-gcc/bin/
源码包存放路径:/home/lhc/Qt/src/      (下载的所有包都放到这个目录)
安装输出目录:/home/lhc/Qt/output/
将qt-everywhere-opensource-src-4.8.5.tar.gz  解压两次,分别命名为qt-x11、qt-embedded

将qt-embedded-linux-opensource-src-4.5.0.tar.bz2解压一次,命名为qt-arm

将arm-linux-gcc.tar.gz和tslib-1.4.tar.gz直接解压。

(二)准备工作:

1、提前安装各种软件及依赖库,避免后面碰到错误再安装麻烦

sudo apt-get install g++-multilib libx11-dev libxext-dev libxtst-dev zlib1g-dev lib32ncurses5 lib32z1 libpng-dev autoconf automake libtool


三、编译安装:

(一)arm交叉编译环境搭建
1、解压arm-linux-gcc.tar.gz,移动到/usr/local目录下

$tar vfzx arm-linux-gcc.tar.gz

$sudo mv arm-linux-gcc /usr/local


2、添加用户环境变量,编辑~/.profile,在后面加上export PATH=/usr/local/arm-linux-gcc/bin/:$PATH,这只是添加到当前用户的环境变量中,如果切换了用户就没有这个环境变量了,如果想所有用户都有这个环境变量应该是添加到/etc/profile文件中。

$echo "export PATH=/usr/local/arm-linux-gcc/bin/:$PATH" >> ~/.profile


3、测试,source ~/.profile使环境变量在当前终端立即生效,重启后会在当前用户所有终端生效。arm-linux-gcc -v会看到当前arm-gcc的版本。
错误:$ arm-linux-gcc -v
/usr/local/arm-linux-gcc/bin/arm-linux-gcc: 15: exec: /usr/local/arm-linux-gcc/bin/.arm-none-linux-gnueabi-gcc: not found
解决方法:$sudo apt-get install g++-multilib

重启一下,再往下进行

(二)Qt及各种工具编译安装

1、x11版本的编译

  首先配置,命令为:
  ./configure -prefix /home/lhc/Qt/output/qt-x11
  然后输入“o”,在然后输入“yes”,下面的embedded版本和arm版本配置时也是一样。
  执行后会出现错误:

  出错:Basic XLib functionality test failed!
  解决方法:sudo apt-get install libx11-dev libxext-dev libxtst-dev

  然后:  make && make install
  出错:error: ‘insert’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation
  解决办法:按照note提示,将./tools/porting/src/codemodel.h中的insert改为this->insert,重新编译


  编译会持续较长时间,取决与你电脑的配置高低,这里有个窍门,假如你PC机的CPU是双核的话,将make指令加上 -j3参数,会进行多线程编译,编译速度会大大提高,即make -j3,这时会使用两个核心同时编译,大家可以试试;编译完成后qt的x11版本会被安装在/home/lhc/Qt/output/qt-x11目录;
  这时还没与完,关键的qvfb程序还没有被编译,所以继续:
  安装qvfb
  cd tools/qvfb
  make

错误:GD5Ev]+0x2ae): undefined reference to `png_write_chunk'
qanimationwriter.cpp:(.text._ZN19QAnimationWriterMNGD0Ev[_ZN19QAnimationWriterMNGD5Ev]+0x2cc): undefined reference to `png_set_filler'
collect2: error: ld returned 1 exit status
Makefile:170: recipe for target '../../bin/qvfb' failed
解决方案:根据http://www.linuxidc.com/Linux/2014-02/97344.htm得知解决办法为
#ln -s /lib/x86_64-linux-gnu/libpng12.so.0 /lib/x86_64-linux-gnu/libpng.so
修改Makefile文件,#gedit Makefile(或者 #vi Makefile),在LIBS后面添加-L/lib/x86_64-linux-gnu -lpng这两项
重新make
然后将在/home/lhc/Qt/src/qt-x11/bin目录生成的qvfb程序,将它复制到电脑的/usr/sbin目录,以后可以直接在终端执行了。


2、embedded版本的编译
(1)配置:
./configure -no-largefile -no-accessibility -no-qt3support -no-phonon -no-svg -no-nis -no-cups -qvfb -prefix ~/Qt/output/qt-embedded
(2)配置完成后:
 make -j3
 make install
  一般不会出现任何错误的。
Makefile:559: recipe for target 'sub-examples-make_default-ordered' failed
make: *** [sub-examples-make_default-ordered] Error 2

最后有个错误,暂时忽略


3、tslib的编译
(1)首先:
  export PATH=/usr/local/arm-linux-gcc/bin/:$PATH
  export PREFIX=/home/lhc/Qt/output/tslib
  export CC=/usr/local/arm-linux-gcc/bin/arm-linux-gcc

(2)./etc/ts.conf配置(当前目录为tslib的根目录)

将module_raw input前面的#去掉,注意module_raw input前面不要留空格,否则会段错误。

# Uncomment if you wish to use the linux input layer event interface
module_raw input

(3)配置
 ./autogen.sh
出现错误:./autogen.sh: 4: autoreconf: not found
解决方法:
sudo apt-get install autoconf automake libtool

然后重新:./autogen.sh


然后:
echo "ac_cv_func_malloc_0_nonnull=yes" > arm-linux.cache
./configure --host=arm-linux --prefix=/home/lhc/Qt/output/tslib --cache-file=arm-linux.cache
错误:checking for arm-linux-g++... arm-linux-g++
checking whether the C++ compiler works... no
configure: error: in `/home/lhc/Qt/src/tslib':
configure: error: C++ compiler cannot create executables
See `config.log' for more details
我们仔细查看config.log从中发现检测g++时发现缺少了依赖库libraries: libz.so.1,查阅apt找到安装这个依赖库的方法在下面。
解决方案:sudo apt-get install lib32z1
若安装提示不成功,并列出了替代的包,那就按照要求安装替代包。

配置完成后:make && make install


4、arm版本的编译
(1)首先配置:

./configure -embedded arm -xplatform qws/linux-arm-g++ -depths 4,8,12,16 -no-qt3support -no-qvfb -qt-mouse-tslib -prefix /home/lhc/Qt/output/qt-arm/ -qt-sql-sqlite -I/home/lhc/Qt/output/tslib/include -L/home/lhc/Qt/output/tslib/lib -no-rpath -no-largefile


(2)然后:make


出现错误:../../corelib/tools/qbytearray.cpp:54: fatal error: zlib.h: 没有那个文件或目录

解决办法:sudo apt-get install zlib1g-dev


然后重新:make -j3

编译完成之后make install

5、添加环境变量

(1)到/home/lhc/Qt/output/qt-arm/bin下

将qmake复制为qmake-arm

cp qmake qmake-arm

(2)添加环境变量

$gedit ~/.profile

添加

export PATH=/home/lhc/Qt/output/qt-arm/bin:$PATH

export PATH=/home/lhc/Qt/output/qt-embedded/bin:$PATH

重启生效

之后qmake && make就可以生成桌面程序

qmake-arm && make就可以生成arm开发板上运行的程序


四、测试

(一)安装一个qtcreator

(二)用qt创建一个带界面的工程

(三)在工程目录下打开终端,qmake-arm,然后make,生成的程序就可以放到开发板上运行测试了。

想要实现在开发板上远程调试,请看我后面写的文章。


该文主要参考文章:Qt-4.6.3移植与Qt creator开发环境建立开发

如何安装arm-linux-gcc

error while loading shared libraries: libz.so.1: cannot open shared object file
各个版本的包的下载地址:Qt
GCC

1 0
原创粉丝点击