Qt Raspberry Pi Cross compilation Loop development environment (with multiple EXE tools download link)

Source: Internet
Author: User
Tags in degrees raspbian jessie

Two days before the start of a 2.8 ' TFT LCD screen, so and the Raspberry Pi connected to the success of the command line displayed on this small poor screen, think this screen shows a black and white content is too wasteful, so consider developing a "face" (GUI). First consider using C or Python to heap the graphical interface, but found whether the C language graphics library SDL or OpenGL to heap the goods are a bit troublesome, after all, I do not want to show a too complex graphical interface on that screen, just display a basic text number is satisfied. So consider the QT library. The QT for Win32, which has been studied for some time before, is very well built, and the installation of the installation package is done from the Http://www.qt.io. At that time, I remember that QT seems to support the development of embedded, while in degrees Niang that consultation to someone once in the Raspberry Pi developed a QT, but that very unfortunate is running on the StartX desktop, but I do not want to run the goods, and he is directly on the Raspberry Pi installed QT, compiled, executed, Need an absolutely enough resolution screen, however my 240x320 screen shows a qt creator is obviously too crowded ... So I found someone on the web doing QT cross-compiling, as for what is cross-compiling:

Cross-compiling
Simply put, the executable code on the other platform is generated on one platform. One question that is often asked is, "Now that we have a host compiler, why cross-compile?" In fact, the answer is simple. Sometimes it is because the target platform is not allowed or unable to install the compiler we need, and we need some features of this compiler, sometimes because the destination platform is resource-poor, unable to run the compiler we need, and sometimes because the destination platform has not been established, even the operating system is not, There is no compiler to run at all.
Another question that is often asked is: "Since you can cross-compile, what do you want the host to compile?" "In fact, the answer is very simple, cross-compiling is the last resort!" Cross-compilation is more restrictive than host compilation, although in theory we can do any form of cross-compiling, but in fact, due to patents, copyrights, technology limitations, it is not always possible to cross-compile, especially in amateur conditions!


Cross-compilation is a bit like the process of developing a single-chip microcomputer, writing-compiling-deploying-running. This solves the bug that my Raspberry Pi screen is too small. Then consider the path of cross-compilation.

1. Tool Preparation

Here consider compiling a Linux program development environment for ARM cores in a Win32 environment. So it takes two things: Cross-toolchain and MinGW.

    • Raspberry Pi Cross-toolchain

What is a toolchain? Toolchain literally means the development tool chain (set), with this goods, we can do some and the operating system related to the thing. This toolchain is https://downloads.raspberrypi.org/raspbian_latest.
First, you need to look at what version of the operating system The Raspberry Pi (2) runs on. There are currently two versions supported, one is the newer Raspbian Jessie, the other is the older Raspbian Wheezy. For newer system versions, the toolchain that need to be downloaded is raspberry-gcc-4.9.2-r2; for older operating systems, the toolchain to download is raspberry-gcc4.6.3. Here, I'm releasing two links, which are toolchain addresses that can be downloaded directly to the system:

GCC for Rasbian Jessie (Raspberry-gcc4.9.2-r2.exe)

Size: 432MB

Download Now

GCC for Rasbian Wheezy (Raspberry-gcc4.6.3.exe)

Size: 111MB

Download Now


When we download is complete, perform the installation:

    • MinGW for Win32

MinGW if has developed the open source software The Netizen should be very familiar, this is the WIN32 environment compiler. Used here to compile some Win32 QT tools (such as Qmake).

MinGW32 GCC

Size: 106MB

Download Now


After the download is complete, install the same as toolchain.

    • Qt 5.5.0 Source Code

QT official does not provide the compiled QT embeded for Raspbian installation package, we need to compile these content, here to download QT source code package.

    • Python for Win32

Python, is used to compile the online debugger.

2. Configure Raspbian

Here is not the Raspberry Pi operating system How to pretend to explain, the internet is similar, Baidu can do it by itself.
QT runs depend on some libraries:

1 sudo apt-get install libxcb1 libxcb1-dev libx11-xcb1 libx11-xcb-dev libxcb-keysyms1 libxcb-keysyms1-dev libxcb-image0 libxcb-image0-dev libxcb-shm0 libxcb-shm0-dev libxcb-icccm4 libxcb-icccm4-dev libxcb-sync1 libxcb-sync-dev libxcb-render-util0 libxcb-render-util0-dev libxcb-xfixes0-dev libxrender-dev libxcb-shape0-dev libxcb-randr0-dev libxcb-glx0-dev

If the above operation fails, you can perform the following:

1 apt-get-update

In the above installed library inside there are two called Libxcb-sync1 Libxcb-sync-dev package, and can not directly through the Apt-get installation, but I passed the degree of Niang searched for a long time also did not see the available packages, so I directly give up the installation, there is no abnormal place.

3. Synchronizing Linux for ARM

Since the last thing to compile is to run on the Raspberry Pi, it relies on some of the Raspberry Pi libraries, so it will be used in the process of compiling and subsequent development.
Open Updatesysroot.bat in C:\Qt\QtEmbeded5.5.0\Raspberry\TOOLS

According to their own synchronization experience, it is recommended that the Raspberry Pi on some irrelevant, may go to the Raspberry Pi scrap can not be used in the bundled software before synchronization to uninstall, so that in the synchronization of time will make the city time is shorter. Recommended uninstall content has wolfram-engine (a mathematical modeling software, this goods can run I feel very magical), SONIC-PI (sound programming, children used to spell a small rhythm of the software), MINECRAFT-PI (My World Raspberry Pi severely castrated version, can play, But without the HDMI output very hard), python-game (some Python games, not fun), and then sync some of the directories. The check box in the meaning is whether in the transmission process is packaged, I sync when the first time is to use the packaging (not checked), but after a while there is a card dead state, I a power outage, the system is broken, and must be re-done. I recommend it to him, so though it's a little bit slower, it's stable.

4. Compiling qmake

I used to have QT once before, there was a qmake, but tried many times did not use that, and finally chose to recompile the qmake once again.
First to extract the Qt source package to a suitable place (I put it directly in the C:\Qt\QtEmbeded5.5.0 directory), and then open the C:\Qt\QtEmbeded5.5.0\MinGW32\msys\1.0\ Msys.bat, this time should come out a particularly like CMD, but the syntax is used in Linux syntax, to execute some of the Linux format shell files.

then confirm that the code is all unzipped to the current directory, confirming the path to the GCC and ARM-LINUX-GNUEABIHF-GCC tools:

If GCC and ARM-LINUX-GNUEABIHF-GCC are not found, You can set your Windows system PATH environment variable, add c:\Qt\QtEmbeded5.5.0\Raspberry\bin and C:\Qt\QtEmbeded5.5.0\MinGW32\bin

This time the focus comes. In the QT source bundle, the configuration file for the Raspberry Pi Linux type ARM-LINUX-GNUEABIHF does not exist, but can be modified from an existing file: Open Qt-everywhere-opensource-src-5.5.0\ qtbase\mkspecs\linux-arm-gnueabi-g++ The qmake.conf file, replace all arm-linux-gnueabi-with ARM-LINUX-GNUEABIHF.

You are ready to start compiling QT now. QT configuration file has a bug, is not directly cross-compiling our Raspberry Pi qt, and must be divided into two steps, first compiled for the WIN32 environment Qmake, and then compiled for Raspberrypi qt.
Open the qmake.conf file under qt-everywhere-opensource-src-5.5.0\qtbase\mkspecs\win32-g++ and add-U__STRICT_ANSI__ after Cxxflags Mark. The

is then executed in the previously opened Msys:

1234 CD /c/qt/qtembeded5 .5.0 / mkdir build CD build /qt-everywhere-opensource-src-5 .5.0 /configure -platform win32-g++-xplatform linux-arm-gnueabi-g++-release-opengl es2-device linux-rasp-pi-g++-sysroot C: /qt/qtembeded5 .5.0 /raspberry/arm-linux-gnueabihf/sysroot -prefix /usr/local/qt5

Then get a hint like this:

After selecting OpenSource and yes to agree to all the terms of the agreement, start compiling the qmake, and then prompt after the compilation is complete:

5. Cross-compiling the Raspberry Pi qt

Before you start cross-compiling for the Raspberry Pi, you need to modify the Configure file.
There is an if true then in the 3900 line of the Qt-everywhere-opensource-src-5.5.0\qtbase\configure file, which causes the qmake to be compiled by default every time the compilation is done. However, after compiling the qmake can not continue to compile, so we are divided into two steps to do, we have already compiled a good qmake, so here to change to:

38943895389638973898389939003901390239033904 setBootstrapVariable(){    getQMakeConf "$1" | echo ${2-$1} = `if [ -n "$3" ]; then sed "$3"; else cat; fi` >> "$mkfile"}# build qmakeif [ ‘!‘ -f "$outpath/bin/qmake.exe" ]; then    echo "Creating qmake..."    mkdir -p "$outpath/qmake" || exit    # fix makefiles

As shown in the following:

Ok, then the makefile configuration file is created for QT compilation. In the Just Msys window, execute:

1 /qt-everywhere-opensource-src-5 .5.0 /configure -platform win32-g++-xplatform linux-arm-gnueabi-g++-release-opengl es2-device linux-rasp-pi-g++-sysroot C: /qt/qtembeded5 .5.0 /raspberry/arm-linux-gnueabihf/sysroot -prefix /usr/local/qt5 -device-option cross_compile=c: /qt/qtembeded5 .5.0 /raspberry/bin/arm-linux-gnueabihf- -QT-XCB

After execution and just the same, select OpenSource and agree to all agreement terms:

After you select OpenSource and agree to all the terms, configure starts checking and creating the makefile file. If the current compilation environment is missing some necessary libraries and files, you will also be prompted. If a class library and file cannot be found, check to see if the following records are all included in the C:\Qt\QtEmbeded5.5.0\Raspberry\arm-linux-gnueabihf\sysroot\etc\ld.so.conf:

12345 /opt/vc/lib/lib/arm-linux-gnueabihf/usr/lib/arm-linux-gnueabihf/usr/lib/arm-linux-gnueabihf/libfakeroot/usr/local/lib

When the creation is complete, you will see that configure lists all the modules that can be compiled for us:

Here, the most painful phase will begin. We're going to start a really real QT compilation phase. After confirming that all required modules are in a compiled state, execute the Make&&make install.
According to a foreign article, it will probably take a few hours, I spent about 7 hours to complete the compilation and installation.

After the start of the compilation, do not move the computer, let him quietly to run. Based on the results of my first compilation, if you want to see the progress of the compilation, you can look at the number of files in our build directory build. My first compilation results in a total of 12,817 files, through the build folder in the number of files statistics, roughly can determine the progress of the compilation.

After a compilation of n hours, finally, Msys back to the command line, which means the compilation is complete.

Here, our compilation work is done. Start configuring the development environment below.

6. Sync Qt5 to Raspberry Pi and test

There is a smartty in the previously installed Raspberrypi toolchain Tools directory, which is opened and connected to the Raspberry Pi ssh.

SFTP uploads are not recommended here because SFTP does not fully upload file attributes to the Raspberry Pi (according to a netizen), so use the Smartty upload function. Set up a directory named Qt5 in the Raspberry Pi/usr/local/before uploading and change its owner to the user you used to log in to SSH (the default is pi, I haven't changed, so here's ownership to PI)

123 cd/usr/localsudo mkdir qt5sudo chownpi qt5

When you are done, click Upload a Directory in the SCP menu

Open the Upload window. Configure local directory for C:\QT\QTEMBEDED5.5.0\RASPBERRY\ARM-LINUX-GNUEABIHF\SYSROOT\USR\LOCAL\QT5, remote directory for/USR/LOCAL/QT5, here's one thing to watch out for , which is the bottom check box. If the On-the-fly tar mode synchronization occurs during the previous synchronization system catalog, it is also necessary to change the transfer mode to single-file mode, otherwise it will die ...

When the upload is complete, we can execute a demo on the SSH command line to determine if Qt is configured correctly. Open/usr/local/qt5/examples/widgets/richtext/textedit run./textedit instance, if configured correctly, a text editor will normally appear on the monitor connected to HDMI. If you do not have an HDMI display device on hand, but the Raspberry Pi has a tftlcd screen with an SPI installed and is properly configured to display the console, you can also add a section of code to the QT_QPA_PLATFORM environment variable configuration before the command:

1 QT_QPA_PLATFORM=linuxfb:fb=/dev/fb* ./textedit

Where fb* is the framebuffer file for the TFT screen that you want the output to display. If it is displayed correctly, the QT5 configuration on the Raspberry Pi has been successfully completed.

7.Qt Creator Configuration Development environment

When Qt runs successfully on the Raspberry Pi, you can begin to prepare yourself to develop QT software that runs on the Raspberry Pi.
The QT program generation rules are: the QT Creator Development program generates. Pro and. ui files->qmake generate CPP files with. Pro and. UI files Qmake compiles all CPP files and header files that need to be compiled into makefile files, and uses makefile to start compiling builds.
Therefore, the qmake, compiler, connector information must be communicated to QT Creator, in order to allow QT Creator in the construction of the operation can correctly find the necessary tools. At the same time, some Raspberry Pi information also need to inform QT Creator.

    • Preparing for QT Creator

QT Creator can use QT 5.5.0 for Win32 the qtcreator in that package, or you can download QT Creator using the following connection

Qt Creator 3.6.0 for Windows

Size: 80.4 MB

Download Now

    • Add a device (Raspberry Pi) to the deployment list

Using QT Creator to deploy directly on a Raspberry Pi running QT programs must add the Raspberry Pi to the deployment list. Here, open the options in the QT Creator Tools menu and select the device on the left:

Select the window that pops up the Select device type after adding, the Raspberry Pi belongs to the Universal Linux device, select the Universal Linux device, click Start Wizard

The wizard then pops up to create a generic Linux device, where you enter the SSH address, username, and password for the Raspberry Pi:

When the completion of the password and other information, click Next will be asked to test the connection, followed by a successful connection prompt:

At this point, a device was successfully added to Qt creator.

    • Add Qmake to Qt Creator

Then all QT program compiles need to use the qmake we just compiled, so we need to add it to qtcreator. Open the QT Creator option in the build and run, right-click QT Versions:

There is a QT for Win32 qmake, we need to qmake for QT embeded, click Add to the right, select C:\Qt\QtEmbeded5.5.0\Raspberry\arm-linux-gnueabihf\ Sysroot\usr\local\qt5\bin\qmake.exe. When selected, the QT version tab will have one more item:

    • Add compiler

Compiler compilation results in the current system are programs running on the x86 machine and cannot be run on the Raspberry Pi arm chip, so a compiler needs to be added manually. The compiler here also uses the compilers in the raspberry toolchain that were previously downloaded. Open the compile and build options for QT Creator in the compiler tab:

Click on the right side to add a MinGW compiler, fill in the following information, click on the application (apply):

    • Create a compilation suite (Kits)

When we have all the relevant information in the input, we need to create a compilation suite to do Qmake, compiler, connector can match the use. The Build Suite tab in the options for entering QT Creator:

Click New on the right and fill in the information in:

Some of the information that is filled in:

    • Device type: Universal Linux Device
    • Device: The device that you just created
    • Sysroot:c:\qt\qtembeded5.5.0\raspberry\arm-linux-gnueabihf\sysroot
    • Compiler: The compiler you just created
    • Debugger: None (because not created)
    • QT version: Qt5 just created
    • Qt mkspec:c:\qt\qtembeded5.5.0\raspberry\arm-linux-gnueabihf\sysroot\usr\local\qt5\mkspecs\devices\ linux-rasp-pi-g++

One of the debugger I did not compile, so also did not add, and the single-step debugging feel no use, there is no way, the need for netizens can go to the resources to find ways.
So far, our QT embeded for Raspberry PI development environment has been completed.

8. Frequently asked questions (FAQs)
  1. Chinese font
    Qt in the Raspberry Pi default is no Chinese font, so all in the QT creator set in Chinese to the Raspberry Pi is blank. The solution is simply to copy the font you need to display from your computer's C:\Windows\Fonts folder, upload it to the/usr/local/qt5/lib/fonts directory of the Raspberry Pi, and restart the QT program. Commonly used fonts have simsum, Microsoft Ya Black, the song body of these, all the test in the line
  2. Write Good QT program click Run Prompt Command not Found
    This is because QT does not know that the program should be deployed to the directory on the Raspberry Pi to run, so you will be prompted not to find a command to execute. The solution is to add the following in the project's. Pro file:

    12 target.path=部署目录,譬如/home/pi/injectINSTALLS+=target
  3. The programmed QT program cannot be displayed on the framebuffer during testing.
    This is because QT creator does not add the Qt_qpa_platform variable when executing the program after the deployment is complete, so we need to add this variable to the system variable and add this variable in/etc/profile:

    1 export QT_QPA_PLATFORM=linuxfb:fb=/dev/fb*
9. References
      1. "Cross-compiling Qt Embedded 5.5 for Raspberry Pi 2"
      2. "Qt for Embedded Linux"
      3. Embedded QT platform for Raspberry Pi Raspberry (i)-cross-compile and install QT Embedded 5.5
      4. Embedded QT platform for Raspberry Pi Raspberry (ii)-development and compilation of raspberry QT 5 applications under Windows with Qt Creator
      5. Embedded QT platform for Raspberry Pi Raspberry (iii)-cross-compiling Raspberry pi version gdb with Python

http://www.jerryzone.cn/qt-embeded-raspberrypi/

Qt Raspberry Pi Cross compilation Loop development environment (with multiple EXE tools download link)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.