Vous êtes sur la page 1sur 5

Cross-platform compilation of programming language Golang for

Raspberry Pi
st 3
rd
Moldamurat Khuralay
th
5 Gagarina L. G.
1 Brimzhanova S.S.
Doctoral student 2 year of study of Candidate of technical Sciences, Doctor of technical sciences,
the specialty 6D060200 - associate professor ofthe Foreign Scientific Consultant,
«Informatics» of KSU after Department of Space Technology Professor of the National Research
A.Baitursynov, Kazakhstan, and Technology of the ENU named University «MIET», Russia.
Kostanai. T.: 8-707-639-95-30. after L.N. Gumilev. T.: 8-775-819-
90-33.
E-mail address:
kameshova_88@mail.ru E-mail address:
nd moldamurat@yandex.ru
2 Atanov S. K. th
Supervisor, Doctor of Technical 4 Kobelekov K.S.
Sciences, professor of the ENU Doctoral student 1 year of study of
named after L. N. Gumilev. the specialty «Computers and
software» of the ENU named after
L.N. Gumilev.

computer, Arduino, model B, model B +, HDMI, micro-USB,


operating system of Raspberry Pi, low performance processors,
modified medium, Distributive, Mathematica, Minecraft, Chrome
browser, Go 1.9.3., Bin, Pkg, Src, github, team, project, DIY
ABSTRACT electronics, RCA-RCA, Mike Thomson, Peter Green, modified
Within this article creates a cross-platform compilation of the LXDE, helloworld, FreeBSD, BogoMIPS, ARM processor
Golang programming language for raspberry pi. Golang, or Go version 6, Raspberry Pi A.
supports type safety, the ability to dynamically enter data, and 1 INTRODUCTION
also contains a rich standard library of functions and built-in data
types like arrays with dynamic size and associative arrays. With Programming is the process of creating computer programs.
the help of multi-threading mechanisms, Go simplifies the According to the words of Niklaus Wirth, one of the programming
distribution of computations and network interactions, while languages founder, "Programs = algorithms + data structures".
modern data types open up to the programmer a world of flexible Programming is based on the use of programming languages in
and modular code. The program quickly compiles, while there is a which program source texts are written. Most of the work of
trash collector and reflection is maintained. Golang is a fast, programmers is related to writing source code, testing and
statically typed, compiled language. Dealing with it you have the debugging programs in one of the programming languages.
impression of using dynamically typed and interpreted language. Source texts and executable program files are objects of copyright
A cross-platform compilation of the Golang programming and are the intellectual property of their authors and right holders.
language was created for raspberry pi - a single-board computer. Different programming languages support different programming
KEYWORDS styles (programming paradigms). Choosing the right
programming language for some parts of the algorithm allows you
Golang, raspberry pi, Raspbian, Raspbian Stretch, Raspbian to reduce the time of writing the program and most effectively
Jessie, Github, programming, Go language, single board solve the problem of describing the algorithm. Different
computer, ARM processor, model, operating system, function, languages require a programmer to have a different level of
types, compilation, cross platform, programs, PIXEL (Pi attention to detail when implementing an algorithm. The result of
Improved Xwindows Environment, Lightweight), hardware this requirement is often a compromise between simplicity and
platforms, programming paradigms, algorithms, GOPATH, performance (or between programmer and user time). The only
language compilation, multithreading, syntax, system language directly executed by a computer is machine language
Programming, C ++, multi-core, network machines, full-featured
ICEMIS'19, June 6–8, 2019, Nur Sultan, Kazakhstan
© 2019 Copyright is held by the authors: S. Brimzhanova, S. Atanov,
L. Gagarina, Moldamurat Khuralay, Kobelekov K.S.
Publication rights licensed to ACM.
ACM ISBN 978-1-4503-7212-1/19/06…$15.00
https://doi.org/10.1145/3330431.3330441
ICEMIS'19, June 6–8, 2019, Nur Sultan, Kazakhstan © 2019 Copyright is held by the authors: S. Brimzhanova, S. Atanov,
L. Gagarina, Moldamurat Khuralay, Kobelekov K.S.

(also called machine code and machine command language). power of reflection at runtime. A fast, statically typed, compiled
Initially, all programs were written in machine code, but now this language looks like a dynamically typed, interpreted language.
is practically not done anymore. Instead, programmers write the
source code in one or another programming language, then, using 2 RASPBERRY PI
the compiler, translate it in one or several stages into machine Anyone who is interested in robotics, DIY electronics, has heard
code, ready for execution on the target processor, or in an of Arduino and Raspberry Pi boards. Both are rather popular
intermediate representation, which can be executed by a special boards (single-board computers). Not surprisingly, they are often
translator - a virtual machine. But this is true only for high-level perceived as analogues and even as competing hardware platforms
languages. If full low-level control over the system is required at designed to solve the same tasks. In fact, the Arduino and the
the level of machine instructions and individual memory cells, the Raspberry Pi have many differences. The first thing you should
programs are written in assembly language. The mnemonic pay attention that the Raspberry Pi is a full-featured computer,
instructions of this language are converted one-to-one into the while it is very difficult to call the Arduino as a computer.
corresponding instructions of the machine language of the target
computer processor (for this reason, translators from assembly Raspberry Pi is a single-board computer that means various parts
languages are defined as algorithmically simple translators). The of a computer, which are usually located on separate boards, are
text editor of the programming environment can have specific represented here on one [2]. In addition, this board has a relatively
functionality, such as indexing names, displaying documentation, small size - about 8.5 * 5.5 cm. The product name are combined
syntax highlighting, and visual user interface creation tools. by Raspberry - raspberry and Pi - Pi number. The raspberry image
became the project logo. Raspberry Pi is released in three
Using a text editor, the programmer produces typing and editing variations: A, A +, B and B +. The most popular model is B, B +
the text of the created program, which is called the source code. A is gaining popularity since it has been released recently [3]. The
programming language defines the syntax and initial semantics of newest and cheapest version of A + may be a hit due to its price
the source code. Integrated development environments are [4]. To start working with the Raspberry Pi, in addition to the
currently widely used in the process of programming. They board itself, you will need:
usually include:

• code editor for entering and editing program text;  the
SD card from which the operating system is loaded;

manufacturer recommends using a card from 8 to 32 Gb;
• debugger for debugging (search and elimination of errors);

a monitor or TV with HDMI, DVI or RCA connectors
• translator to convert the text of the program into a machine (for models A and B only), and, accordingly, an HDMI-HDMI
representation; cable,
 HDMI-DVI or RCA-RCA, you can also use an HDMI-
VGA converter;
• linker for building a program from several modules; 
USB keyboard;


• other service modules and tools. USB mouse;


Programming is the art, craft and science of writing programs that Power cable or micro USB battery.
determine how a computer will work. A new player has appeared
3 RASPBIAN
on the programming language market - the Golang programming
language, or Go from Google. Go is a general-purpose language Raspbian is a Debian-based operating system for the Raspberry
with wide capabilities and clear syntax [1]. Thanks to Pi [5]. There are several versions of Raspbian, including Raspbian
multiplatform, reliable, well-documented standard library and Stretch and Raspbian Jessie. Since 2015, the Raspbian has
focus on convenient approaches to the development itself, Go is officially introduced the Raspberry Pi Foundation as the main
the ideal language for the first steps in programming. Google operating system for single-board computers [6] Raspberry Pi.
announced the Go language in 2009, and since then it has changed Mike Thomson and Peter Green as an independent project [7]
a little, but its goals and objectives remain the same: this language created Raspbian. The initial assembly was completed in June
is intended for system programming and is inherently very similar 2012 [8]. The operating system is under active development.
to C ++. The Go language is a compiled and multi-threaded Raspbian is optimized for low-performance ARM processors [9]
general purpose language that has many common features with used in the Raspberry Pi line of computers.
the C ++ language, therefore, for successful mastering of the
presented material, certain knowledge in C ++ is required. Go - PIXEL (Pi Improved Xwindows Environment, Lightweight) is
expressive, concise, clean and effective. Concurrency mechanisms used as the main desktop environment in Raspbian. It consists of a
simplify the writing of programs that make the most of multi-core modified LXDE [10] desktop environment and an Openbox [11]
and network machines [16]. Its new type system provides flexible window manager with a new theme and several other changes.
and modular construction of programs. Go quickly compiles to The distribution comes with a copy of the Mathematica computer
machine code, but has the convenience of trash collection and the algebra program [12], a special version of Minecraft [13] called
ICEMIS'19, June 6–8, 2019, Nur Sultan, Kazakhstan © 2019 Copyright is held by the authors: S. Brimzhanova, S. Atanov,
L. Gagarina, Moldamurat Khuralay, Kobelekov K.S.

Minecraft Pi [14], as well as a lightweight latest version of the


Chrome browser [15]. in some documents. This is usually not required, and Go
automatically uses $ GOPATH / bin / for Go installations.
4 INSTALL GO TO RASPBIAN STRETCH
However, you can also check the path settings (/ home / pi / go /
Install Go to Raspbian Stretch from repositories. The most current bin should be included) to make sure that you can run the code
version for manual installation from downloads is Go 1.9.3. that was installed using go install.
1. Log in to your user on the Raspberry Pi. pi@pi3-2:~ $ echo $PATH

2. It is necessary to install Go (golang): /home/pi/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/s


bin:/bin:/usr/local/games:/usr/games
pi@pi3-2:~ $ sudo apt update
6. Over time, the Go working directory will contain three
pi@pi3-2:~ $ sudo apt install golang
subdirectories: bin, src, and pkg. Except src they will be
3 Create a working directory for all your Go projects in the $ automatically created when it will be needed first time. The
HOME directory. It is best to name it, since it defaults to structure for user pi will look like this:
GOPATH in future versions of Go (starting with Go 1.8):
/home
pi@pi3-2:~ $ mkdir go /pi

4. Intravenously add the $ GOPATH environment variable and /go


modified PATH parameters to .profile:
/src
pi@pi3-2:~ $ echo 'export GOPATH=$HOME/go' >> ~/.profile
/pkg
pi@pi3-2:~ $ echo 'PATH="$HOME/go/bin:$PATH"' >> /bin
~/.profile
Bin - contains all Go executables that were installed using the go
5. Logout and Relog with new settings, then you need to check the install command. Pkg - contains all compiled packages that can
settings:
be imported into projects. Src - will contain all your source files,
pi@pi3-2:~ $ go env either your own, or sources downloaded from external
repositories.
GOARCH="arm"
Let us give an example by running go get
GOBIN="" github.com/petergloor/hello-g - go will automatically select and
GOEXE="" place the source files from the corresponding external Github
repository in the local directory $
GOHOSTARCH="arm" HOME/go/src/github.com/petergloor/hello-go.
GOHOSTOS="linux" Since quite often for extracting external repositories it is
GOOS="linux" important to keep the directory structure always well organized
and clean for both reference and contribution.
GOPATH="/home/pi/go"
In addition, you can organize your projects as long as they are
GORACE="" hierarchically structured below directory $ HOME/go/src/ and
GOROOT="/usr/lib/go-1.7" follow the rules mentioned in the documentation.

GOTOOLDIR="/usr/lib/go-1.7/pkg/tool/linux_arm" If you do not have a github account, you can use any other
external repository account, but it's best to use your Github
CC="gcc" account to clearly define your projects.
GOGCCFLAGS="-fPIC -marm -pthread -fmessage-length=0 - 7. Add the "hello world" project to verify the installation.
fdebug-prefix-map=/tmp/go-build187598155=/tmp/go-build -gno-
record-gcc-switches" a) First create a project folder and cd in its directory.

CXX="g++" pi@pi3-2:~ $ mkdir -p $HOME/go/src/pi/helloworld

CGO_ENABLED="1" pi@pi3-2:~ $ cd $HOME/go/src/pi/helloworld pi@pi3-

Especially make sure that GOPATH points to the previously 2:~/go/src/pi/helloworld $


created working directory Go. Do not install GOBIN, as indicated
ICEMIS'19, June 6–8, 2019, Nur Sultan, Kazakhstan © 2019 Copyright is held by the authors: S. Brimzhanova, S. Atanov,
L. Gagarina, Moldamurat Khuralay, Kobelekov K.S.

b) Using an optional editor, we create a main.go file with the CPU architecture: 7
following contents (Figure 1). CPU variant : 0x0

CPU part : 0xb76


CPU revision :7
Hardware : BCM2708
Revision : 000f
Serial : 00000000aa0b36f1
In this case there is the ARM processor version 6. And the
compilation parameters will be as follows: # GOOS=linux
GOARCH=arm GOARM=6 go build
pi@pi3-2:~/go/src/pi/helloworld $ ls
helloworld main.go
pi@pi3-2:~/go/src/pi/helloworld $
f) Now you can run it.
Figure 1. File creation
pi@pi3-2:~/go/src/pi/helloworld $ ./helloworld
At this point, the interval does not matter. Go provides a good tool
for this matter. Hello raspberry pi! Greetings from Raspberry Pi

c) Now run the program. pi@pi3-2:~/go/src/pi/helloworld $

pi@pi3-2:~/go/src/pi/helloworld $ go run main.go g) Install the program in the directory $ HOME/go/bin/.

Hello raspberry pi! Greetings from Raspberry Pi pi@pi3-2:~/go/src/pi/helloworld $ go install

pi@pi3-2:~/go/src/pi/helloworld $ pi@pi3-2:~/go/src/pi/helloworld $ ls $HOME/go/bin

If you receive an error message, you need to fix it urgently! hello-go helloworld
Carefully check the spelling and cases (Go is case sensitive). pi@pi3-2:~/go/src/pi/helloworld $
d) Next you should format the code: h) If everything is done correctly, it can be started by our user pi
pi@pi3-2:~/go/src/pi/helloworld $ go fmt from anywhere, just by typing the command name:

Without a filename, it will correctly (re-) format all source files in pi@pi3-2:~/go/src/pi/helloworld $ helloworld
this directory and below. Hello world! Greetings from Raspberry Pi
e) Then create a helloworld as an executable procram, inside this pi@pi3-2:~/go/src/pi/helloworld $ cd ~
directory.
pi@pi3-2:~ $ helloworld
To compile the source code on go and then run the resulting
binary on raspberry pi, you need to set certain env-variables Hello world! Greetings from Raspberry Pi
before compiling. pi@pi3-2:~ $
For different versions of Raspberry Pi you need to specify Currently, go language support is on Windows, Linux, MacOS
different versions of ARM. You can find out exactly what you and FreeBSD platforms. Due to this article wascreated golang
need in / proc / cpuinfo: executable code for ARM processors. In addition to the compiler
# cat /proc/cpuinfo from Google, there is also the gccgo compiler from the GNU
collection.
Processor : ARMv6-compatible processor rev 7 (v6l)
REFERENCES
BogoMIPS : 697.95
[1] Go programming language - [Electronic resource],
Features : swp half thumb fastmult vfp edsp java tls
URL: https://golang.org/.
CPU implementer : 0x41
ICEMIS'19, June 6–8, 2019, Nur Sultan, Kazakhstan © 2019 Copyright is held by the authors: S. Brimzhanova, S. Atanov,
L. Gagarina, Moldamurat Khuralay, Kobelekov K.S.

[2] Raspberry Pi - [Electronic resource], URL:


https://ru.wikipedia.org/wiki/Raspberry_Pi.
[3] New version of Raspberry Pi B+ - [Electronic resource],
URL: http://edurobots.ru/2014/07/vyshla-novaya-versiya-
raspberry-pi/
[4] New version of Raspberry Pi A+ - [Electronic resource],
URL: http://edurobots.ru/2014/11/vyshla-novaya-versiya-
raspberry-pi-a-za-20/
[5] Debian — operating system - [Electronic resource],
URL: https://ru.wikipedia.org/wiki/Debian

[6] Single board computer - [Electronic resource], URL:


https://ru.wikipedia.org/wiki/ Single board _ computer .
[7] RaspbianAbout - Raspbian. - [Electronic resource],
URL: www.raspbian.org.

[8] FrontPage - Raspbian.- [Electronic resource], URL:


www.raspbian.org.
[9] ARM (architecture). - [Electronic resource], URL:
https://ru.wikipedia.org/wiki/ARM_( architecture)
[10] LXDE (Lightweight X11 Desktop Environment) — free
desktop environment. - [Electronic resource], URL:
https://ru.wikipedia.org/wiki/LXDE
[11] Openbox — free window manager for the X Window
System. [Electronic resource], URL:
https://ru.wikipedia.org/wiki/Openbox
[12] Mathematica — computer algebra system. [Electronic
resource], URL: https://ru.wikipedia.org/wiki/Mathematica
[13] Minecraft. [Electronic resource], URL:
https://ru.wikipedia.org/wiki/Minecraft

[14] Mathematica and Wolfram Language are licensed


under this release with permission from Wolfram Research, Inc.,
and may only be used for non-commercial purposes. [Electronic
resource], URL: raspberrypi.org Download Raspbian for
Raspberry Pi
[15] Introducing PIXEL - Raspberry Pi - [Electronic
resource].

[16] Ioannidi K., Christakis Ch., Sautbekov S., Frangos P.,


Atanov S.K. The radiation problem from a vertical short dipole
antenna above flat and loss ground. Novel formulation in the
spectral domain with closed form analytical solution in the high
frequency regime, International Journal of Antennas and
Propagation, Volume 2014 (2014), Article ID 989348, ISSN
1687-5869

Vous aimerez peut-être aussi