Sie sind auf Seite 1von 6

Report: Cross Compiling for the Raspberry Pi

Ajla Sokol, Emina Topalovi¢, Faruk Bozkurt

April 25, 2018

1
Introduction

Cross-development is a practice for software product development that is com-


monly used today. The idea behind the cross-development is that a software
application or product should work well in more than one specic digital habitat.
This approach is used to set up the Raspberry Pi as well.
Raspberry Pi is a single board computer, a small computer with so many
uses. It has a quad-core arm CPU (Central Processing Unit), single gigabyte
of RAM (Random-access Memory), 4 USB and 2 HDMI Ports and Ethernet
jack a micro SD slot for storage, wireless and Bluetooth, combined video and
headphone jacks.
What really makes that little computer interesting is 40-pin general purpose
input and output, or GPIO. What it allows us to do is to connect the Raspberry
nearly anywhere. This functionality was built by default so Raspberry Pi can
be used to teach computer science and programming. Raspberry Pi can be used
for nearly for any basic home projects, for example, for home entrance (to create
smart door lock), we can create our own wireless extender or media center for
our TV can be created. Making a long story short, Raspberry Pi can be simply
used in all areas of making the daily life more convenient.
The idea behind this project was to set up the Raspberry Pi, set up cross
build tools, and implement Hello, World! code from the Raspberry Pi.

Assembly of Raspberry Pi

The rst step before the cross-development is to assembly the components to-
gether, to get a Raspberry Pi inside the case with the 3.5 inch monitor on the
top.
To ensure that the processors do not overheat in case of the larger pro-
grammes that are being run by it, it was neccessary to place the heat sinks on
them. This was done by placing the double sided tape onto heat sinks, and
placing them on the processors. Heat sink will ensure the regulation of the
temperature of the device, and stabilize it to the optimal level.
When nishing up with the heat sinks implementation, the monitor is added
onto the Raspberry Pi. This is a 3.5 inch RPi Display Touch monitor that
allows us a nice communication with our Raspberry Pi. Display is set up to
sink into the general purpose input and output (GPIO) part of our computer,
and it is connected by the HDMI to HDMI converter (male to male adapter),
that is pluged in the monitors and Raspberry Pi's HDMI port simultaneously.
To ensure that the screen and computer stays safe, it is placed into the case
that we screwed on placing these two safely and tightly together.
Next step was to plug in the keyboard, mouse, place in SD card with the
operating system inside, and power up the Raspberry Pi.
To install the working operating system for our computer, rst step is to
download the NOOBS, or New Out Of The Box Software, from the Raspberry
Pi site. This software will allow us to choose from the range of the operating

2
systems for our computer. The default operating system is Rasbian, that we
installed onto the Raspberry Pi.

Cross-Development

Since our host computer was based on the Windows operating system, we install
the virtual machine (Virtual Box) to use as the Ubuntu that is needed for our
cross compilation. We used the Ubuntu 16.04 on the laptop to ensure that the
cross-development goes smoothly, and followed the steps from the internet links
that were provided to us.
First step was to install build tools, C and C++ compire and build tools
for the Pi's ARM processor, and debugging tool. These are three lines of codes
that we entered into terminal:

• sudo apt-get install build-essential

• sudo apt-gt install g++-arm-linux-gnueabihf

• sudo apt-get install gdb-multiarch

• arm-linux-gnueabihf-g++ -v

The last command entered was to check if the G++ compiler is installed. Af-
terwards, we made a simple hello.cpp le inside the directory that was created.
The source code looks as follows:

• #include <iostream>

• using namespace std;

• int main()

• {

• int a=2;

• int b=5;

• int c=a+b;

• cout << c << endl;

• cout << Hello World!<< endl;

• return 0;

• }

Firstly, we changed the directory using -cd command, so that we could create
the compilation le of the one we wrote down as the source code. Then, we
used following code lines to implement that le:

3
• arm-linux-gnueabihf-g++ -O3 -g3 -Wall -c -fPIC -o hello.o hello.cpp

• arm-linux-gnueabihf-g++ -o hello hello.o

Figure 1: Building executable le

The next step is to move this le to our Raspberry Pi. Now, we set up the
Raspberry Pi connection by using gdbserver. This is the way of connecting our
system to the host computer via IP address and port number. IP address used
here was the IP address of our Virtual Box through the wireless network, that
was found using ipcong on the Windows command prompt. The code entered
in terminal of Raspberry Pi is following:

• gdbserver multi 192.168.56.1:5353

Now, our system is listening to this port in order to establish connection. We


are able to send the le to our system.
In order for scp command (the command that will be used to move executable
le to Raspberry Pi) to be valid, rst thing is to enable the ssh terminal in the
settings of Raspberry Pi. The next step is to use this command, and move our
executable le to the directory that was created there. The code that helped us
do this is following:

• scp hello pi@10.0.203.42:/home/pi/emina/hello

Figure 2: Copying les to Raspberry Pi

Hello is the name of the executable le that we want to move, pi is the name
of the system we want to move it to together with the IP address of it, and
the other part is the path of the directory that we want to move it to, together
with the name of le that will be executed. It also looked for password of the
Raspberry Pi (it is, by default, raspberry). We see that the output shows us
that the 100% of le was moved.
The transfer of le could also be done using USB, but this way is more suit-
able and convenient way for future use as well. Since we use gdb for debugging,
we now enter this command on our host computer as well in order to establish
connection and debug and run the executable program. Code is following:

• gdb-multiarch

• target extended-remote 10.0.203.42:5353

4
• set remote exec-le emina/hello

• le hello

• run

Figure 3: Execution of program

As we can see from the gure, the program was run successfully, and our
outputs (the outputs were number 7 and line Hello World!) were shown on
the Raspberry Pi terminal.
To see that we could access the code, and check the variables inside, we used
breakpoint to stop the execution at one line, and we tried to access the value of
one integer inside the code. We used command break at line 11, and later on
the command p, where we check for the value of integer a.

5
Figure 4: Breakpoint

As we can see from the gure, when we place breakpoint at some line of our
le (in our case, line 11), the line where breakpoint was made will be shown on
our terminal. The next step was to check if we could see the values inserted in
our le, and if they were correct (in our case, to check the value of the integer
a). It was as expected, it gave correct output based on our source code.

Conclusion

The Hello World example was a good start of understanding cross-debugging


and cross-compiling using our host system and Raspberry Pi. We understood
the basic concepts behind cross-compilation and cross-debugging, and ways to
our Raspberry Pi using laptop. This concept will help us in the future, when
working on our project design, for easier compilation, since our project hardware
is Raspberry Pi based. The next task for our project to be successfull is to focus
on installing Qt creator, and prepare those for cross-compilation as well.

Das könnte Ihnen auch gefallen