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

    xiaoxiao2021-03-25  139

    http://blog.csdn.net/lell3538/article/details/52463744

    一、环境及软件包介绍:

    (一)系统环境

    ubuntu16.04 64位

    (二)软件包  

    1、arm-Linux-gcc 

    我提供的包是arm-cortexa9-linux-gnueabihf-4.9.3-20160512.tar.xz版本。

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

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

    3、target-qte-4.8.6-to-hostpc.tgz

    这是qt4.8.6用于编译嵌入式的qt。友善支臂提供。

    4、qt-creator-opensource-linux-x86_64-4.2.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.7.tar.gz  解压两次,分别命名为qt-x11、qt-embedded

    将arm-linux-gcc安装好;

    (二)准备工作:

    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交叉编译工具

    2、添加用户环境变量,编辑~/.bashrc,在后面加上export PATH=/xxx/xxx/arm-linux-gcc/bin/:$PATH,这只是添加到当前用户的环境变量中,如果切换了用户就没有这个环境变量了,运行. ~/.bashrc生效 。

    重启一下,再往下进行

    (二)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 ~/.bashrc

    添加

    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创建一个带界面的工程

    (三)构建开kit就可以进行开发测试了。

    转载请注明原文地址: https://ju.6miu.com/read-9710.html

    最新回复(0)