交叉编译qt4.8.4 for ARM

时间:2021-06-02 19:56:40

所需工具:

  交叉编译工具:arm-linux-gcc 4.4.3

  qt4.8.4源码包:qt-everywhere-opensource-src-4.8.4.tar.gz

编译:

  解压qt4.8.4源码包:

tar -zxvf qt-everywhere-opensource-src-4.8.4.tar.gz

  设置交叉编译工具链,修改文件/qt-everywhere-opensource-src-4.8.4/mkspecs/linux-arm-gnueabi-g++ /qmake.conf,修改内容如下:  

# modifications to g++.conf
QMAKE_CC = arm-none-linux-gnueabi-gcc
QMAKE_CXX = arm-none-linux-gnueabi-g++
QMAKE_LINK = arm-none-linux-gnueabi-g++
QMAKE_LINK_SHLIB = arm-none-linux-gnueabi-g++

# modifications to linux.conf
QMAKE_AR = arm-none-linux-gnueabi-ar cqs
QMAKE_OBJCOPY = arm-none-linux-gnueabi-objcopy
QMAKE_STRIP = arm-none-linux-gnueabi-strip

  生成Makefile:

./configure -prefix /usr/local/qt-4.8.4-for-arm -embedded arm -host-little-endian -no-cups -no-3dnow -nomake examples -nomake demos -nomake docs -xplatform /qws/linux-arm-g++

  编译:

make  #此过程大概需要两个多小时
make install 

  修改环境变量,在~/.bashrc中添加以下语句

export ARMQTDIR=/opt/qt-4.8.4-for-arm
export PATH=$ARMQTDIR/bin:$PATH
export LD_LIBRARY_PATH=$ARMQTDIR/lib
export QMAKESPEC=/opt/qt-4.8.4-for-arm/mkspecs/qws/linux-arm-g++

  重新加载~/.bashrc:

source ~/.bashrc

  检查是否成功:

qmake -v
#输出以下信息:
#QMake version 2.01a
#Using Qt version 4.8.4 in /opt/qt-4.8.4-for-arm/lib

which qmake
#输出:
#/opt/qt-4.8.4-for-arm/bin/qmake

    测试代码:

/*main.cpp*/

#include "mainwindow.h"
#include <QApplication>

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    MainWindow w;
    w.show();
    
    return a.exec();
}
/*mainwindow.cpp*/

#include "mainwindow.h"
#include "ui_mainwindow.h"

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}
/*mainwindow.h*/

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QMainWindow>

namespace Ui {
class MainWindow;
}

class MainWindow : public QMainWindow
{
    Q_OBJECT
    
public:
    explicit MainWindow(QWidget *parent = 0);
    ~MainWindow();
    
private:
    Ui::MainWindow *ui;
};

#endif // MAINWINDOW_H
<!-- mainwindow.ui -->

<ui version="4.0">
 <class>MainWindow</class>
 <widget class="QMainWindow" name="MainWindow" >
  <property name="geometry" >
   <rect>
    <x>0</x>
    <y>0</y>
    <width>400</width>
    <height>300</height>
   </rect>
  </property>
  <property name="windowTitle" >
   <string>MainWindow</string>
  </property>
  <widget class="QMenuBar" name="menuBar" />
  <widget class="QToolBar" name="mainToolBar" />
  <widget class="QWidget" name="centralWidget" />
  <widget class="QStatusBar" name="statusBar" />
 </widget>
 <layoutDefault spacing="6" margin="11" />
 <pixmapfunction></pixmapfunction>
 <resources/>
 <connections/>
</ui>

执行qmake生成Makefile,然后make编译:

qmake qttest.pro

make

如果编译通过无错误,说明成功了。