File: tutorial-install-crosscompiling-raspberry.dox

package info (click to toggle)
visp 3.6.0-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 119,296 kB
  • sloc: cpp: 500,914; ansic: 52,904; xml: 22,642; python: 7,365; java: 4,247; sh: 482; makefile: 237; objc: 145
file content (360 lines) | stat: -rw-r--r-- 15,986 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
/**

\page tutorial-install-crosscompiling-raspberry Tutorial: Cross-compilation for Raspberry Pi from Ubuntu host
\tableofcontents

Compiling ViSP directly on your Raspberry Pi will take a lot of time.
In this tutorial you will learn how to cross-compile ViSP from source on an Ubuntu 14.04 host for a <a href="http://www.raspberrypi.org/help/what-is-a-raspberry-pi">Raspberry Pi 1, 2 or 3</a> target.

Adapting this tutorial for other linux hosts (Fedora, Linux Mint, Debian...) should not be too complicated.

The material that is here involved is the following:
- a \b host computer running Ubuntu 14.04 where we will cross-compile ViSP that will then be used on your Raspberry Pi
- a Raspberry Pi board that will the \b target.

\note Concerning ViSP installation on Raspberry Pi, we provide also this other \ref tutorial-install-raspberry.

\section cross_raspberry_setup Setting up Raspberry Pi target

There are a lot of documentation and tutorial that explain different ways to setup a Raspberry Pi. A good reference is the official page <a href="http://www.raspberrypi.org/">http://www.raspberrypi.org</a>

We suppose here that you have a Raspberry Pi board that is already running.

Depending on you application or usage, you may want to install some 3rd parties useful to enable some ViSP capabilities. We recommend to install the following on your Raspberry Pi:

- OpenCV
\verbatim
$ sudo apt-get install libopencv-dev
\endverbatim
- libX11 to be able to open a window to display images
\verbatim
$ sudo apt-get install libx11-dev
\endverbatim
- lapack to benefit from optimized mathematical capabilities
\verbatim
$ sudo apt-get install liblapack-dev
\endverbatim
- libv4l to grab images from usb or analogic cameras
\verbatim
$ sudo apt-get install libv4l-dev
\endverbatim
- QR code detection
\verbatim
$ sudo apt-get install libzbar-dev
\endverbatim

\section cross_raspberry_host Setting up Ubuntu host computer

\subsection cross_raspberry_host_toolchain Install Raspberry official toochain

\note Everything in this section is to run on your Ubuntu host computer.

Start with making a folder in your home directory called \c raspberrypi.
\verbatim
$ mkdir -p $HOME/soft/raspberrypi
\endverbatim

Go in to this folder and pull down the offical Raspberry tools folder.
\verbatim
$ cd $HOME/soft/raspberrypi
$ git clone git://github.com/raspberrypi/tools.git --depth=1
\endverbatim

The toochain that will be used is located in \c $HOME/soft/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian. Add now toolchain binaries location to your \c PATH adding
\verbatim
export PATH=$PATH:$HOME/soft/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin
\endverbatim
to the end of the file named \c ~/.bashrc

Now you can either log out and log back in (i.e. restart your terminal session), or run \c . \c ~/.bashrc in your terminal to pick up the \c PATH addition in your current terminal session.

Now, verify that you can access the compiler \c arm-linux-gnueabihf-g++.

\verbatim
$ arm-linux-gnueabihf-g++ --version
\endverbatim

You should get something like this:
\verbatim
arm-linux-gnueabihf-g++ (crosstool-NG linaro-1.13.1-4.8-2014.01 - Linaro GCC 2013.11) 4.8.3 20140106 (prerelease)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
\endverbatim

\subsection cross_raspberry_host_rsync Install Raspberry Pi sysroot

This step is mandatory to cross-compile ViSP with the 3rd parties that are already installed on the Raspberry target.

In your raspberrypi folder, make a folder called \c rootfs.

\verbatim
$ mkdir $HOME/soft/raspberrypi/rootfs
\endverbatim

Now you need to copy via \c rsync the entire Raspberry \c /lib and \c /usr directories to this newly created folder.

\verbatim
$ rsync -rl --delete-after --safe-links pi@192.168.1.PI:/{lib,usr} $HOME/soft/raspberrypi/rootfs
\endverbatim
where \c 192.168.1.PI is replaced by the IP of your Raspberry Pi.

\subsection cross_raspberry_visp_src Get ViSP source code

Cross-compilation capabilities are fully supported since ViSP 3.0.1 release.

There are different ways to get ViSP source code on Raspberry Pi:

- You can download a <a href="https://visp.inria.fr/download#snapshot">daily snapshot</a>. Once downloaded, uncompress the file using
\verbatim
$ tar xvzf visp-snapshot-yyyy-mm-dd.tar.gz
\endverbatim

- Or you get the cutting-edge ViSP from <a href="https://github.com/lagadic/visp">GitHub repository</a> using the following command
\verbatim
$ git clone https://github.com/lagadic/visp.git
\endverbatim

- Or you can download the <a href="https://visp.inria.fr/download">latest release</a> (should be at least 3.0.1) as a zip or a tarball. Once downloaded, uncompress the file using either
\verbatim
$ tar xvzf visp-x.y.z.tar.gz
\endverbatim
or
\verbatim
$ unzip visp-x.y.z.zip
\endverbatim

We suppose now that ViSP source is in a directory denoted \c \<source_dir\>, for example \c $HOME/soft/visp

\subsection cross_raspberry_visp_config Cross-compiling ViSP from source

- Create first a directory denoted \c \<binary_dir\> where you want to cross-compile ViSP. This directory will contain generated Makefiles, object files, and output libraries and binaries that could be later used on the Raspberry Pi.
\verbatim
$ mkdir $HOME/soft/visp-crossbuild
\endverbatim

- Enter \c \<binary_dir\> and configure the build:
\verbatim
$ cd $HOME/soft/visp-crossbuild
$ cmake -DCMAKE_TOOLCHAIN_FILE=../visp/platforms/linux/arm-raspberrypi.toolchain.cmake ../visp
\endverbatim
\note See also \ref cross_raspberry_tips_howto_other_toolchain and \ref cross_raspberry_tips_howto_other_rootfs.

- Cross-compile ViSP
\verbatim
$ make -j4 install
\endverbatim
At this point, depending on your Raspberry version you may encounter the following issues \ref cross_raspberry_tips_libpthread, \ref cross_raspberry_tips_libc, \ref cross_raspberry_tips_libpng, \ref cross_raspberry_tips_gcc_4_9 for which we give some hints to work around.

At the end, the resulting installation is available in\c $HOME/soft/visp-crossbuild

\subsection cross_raspberry_visp_usage Using ViSP cross-compilation result on Raspberry

The result of the cross-compilation could then be used on the Raspberry. We give a brief summary of the steps:

- Copy the cross-build installation to Raspberry Pi target
\verbatim
$ tar cvzf install.tar.gz install
$ scp -r install.tar.gz pi@192.168.1.PI:
\endverbatim

- Usage on Raspberry Pi
First move the libraries that were cross-build to a more friend location
\verbatim
$ ssh pi@192.168.1.PI
pi@raspberrypi:~ $ tar xvzf install.tar.gz
pi@raspberrypi:~ $ mv install visp-crossbuild
\endverbatim
Then as described in \ref tutorial-getting-started create a tutorial-viewer.cpp and the corresponding CMakeLists.txt file in $HOME/started:
\verbatim
pi@raspberrypi:~ $ cd $HOME/started
pi@raspberrypi:~ $ ls
tutorial-viewer.cpp CMakeLists.txt
\endverbatim
Create a build folder:
\verbatim
pi@raspberrypi:~ $ mkdir build
pi@raspberrypi:~ $ cd build
\endverbatim
To configure this project, you may run:
\verbatim
pi@raspberrypi:~ $ cmake .. -DVISP_DIR=/home/pi/visp-crossbuild/lib/cmake/visp
\endverbatim
At this step you may encounter the following issue with a Raspberry Pi 1: \ref cross_raspberry_tips_cmake_version. Once fixed, to build just run:
\verbatim
pi@raspberrypi:~ $ make
\endverbatim

\section cross_raspberry_tips Tips and tricks

\subsection cross_raspberry_tips_howto_other_toolchain How to use an other toochain

The default toolchain used in \c arm-raspberrypi.toolchain.cmake file is the one located in \c $HOME/soft/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin. To set an other toochain, use \c ARM_RASPBERRY_CROSSCHAIN cmake var:
\verbatim
$ cmake -DARM_RASPBERRY_CROSSCHAIN=$HOME/soft/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin -DCMAKE_TOOLCHAIN_FILE=../visp/platforms/linux/arm-raspberrypi.toolchain.cmake ../visp
\endverbatim

Don't forget to update the location of the toolchain in your PATH in \c ~/.bashrc file:
\verbatim
export PATH=$PATH:$HOME/soft/raspberrypi/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin
\endverbatim

\subsection cross_raspberry_tips_howto_other_rootfs How to use an other rootfs location

The default rootfs used in \c arm-raspberrypi.toolchain.cmake file is the one located in \c $HOME/soft/raspberrypi/roots. To set an other location, use \c ARM_RASPBERRY_ROOTFS cmake var:
\verbatim
$ cmake -DARM_RASPBERRY_ROOTFS=$HOME/soft/raspberrypi/root-fs-pi3 -DCMAKE_TOOLCHAIN_FILE=../visp/platforms/linux/arm-raspberrypi.toolchain.cmake ../visp
\endverbatim

\subsection cross_raspberry_tips_libpthread Linker cannot find libpthread.so

During the cross-compilation, if you get the following error:

\verbatim
Linking CXX shared library ../../lib/libvisp_core.so
 .../tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm- linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find /lib/arm-linux-gnueabihf/libpthread.so.0
 .../tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find /usr/lib/arm-linux-gnueabihf/libpthread_nonshared.a
\endverbatim

Do the following:
\verbatim
$ cd $HOME/soft/raspberrypi/rootfs
$ find . -name libpthread.so
./usr/lib/arm-linux-gnueabihf/libpthread.so
\endverbatim

Edit this file to set relative path:

\verbatim
$ vi ./usr/lib/arm-linux-gnueabihf/libpthread.so
OUTPUT_FORMAT(elf32-littlearm)
GROUP ( ../../../lib/arm-linux-gnueabihf/libpthread.so.0 ../../../usr/lib/arm-linux-gnueabihf/libpthread_nonshared.a )
\endverbatim

\subsection cross_raspberry_tips_libc Linker cannot find libc.so

During the cross-compilation, if you get the following error:
\verbatim
.../tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find /lib/arm-linux-gnueabihf/libc.so.6
.../tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find /usr/lib/arm-linux-gnueabihf/libc_nonshared.a
.../tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find /lib/arm-linux-gnueabihf/ld-linux-armhf.so.3
\endverbatim

Do the following:
\verbatim
$ cd $HOME/soft/raspberrypi/rootfs
$ find . -name libc.so
./usr/lib/arm-linux-gnueabihf/libc.so
\endverbatim

Edit this file to set relative path:
\verbatim
$ vi ./usr/lib/arm-linux-gnueabihf/libc.so
OUTPUT_FORMAT(elf32-littlearm)
GROUP ( ../../../lib/arm-linux-gnueabihf/libc.so.6 ../../../usr/lib/arm-linux-gnueabihf/libc_nonshared.a  AS_NEEDED ( ../../../lib/arm-linux-gnueabihf/ld-linux-armhf.so.3 ) )
\endverbatim

\subsection cross_raspberry_tips_libpng No rule to make target libpng.so

If during cross-compilation, you get the error:
\verbatim
make[3]: *** No rule to make target `.../raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libpng.so', needed by `lib/libvisp_io.so.3.0.1'
\endverbatim

It mean that libpng.so is not found. The fix consists in reparing \c libpng12.so link that was miss updated during \c rsync:

\verbatim
$ cd $HOME/soft/raspberrypi/rootfs
$ cd usr/lib/arm-linux-gnueabihf
$ ls -als libpng*
172 -rw-r--r-- 1 fspindle fspindle 175234 juin   7 15:18 libpng12.a
  0 lrwxrwxrwx 1 fspindle fspindle     13 juin   7 15:17 libpng12.so -> libpng12.so.0
  0 lrwxrwxrwx 1 fspindle fspindle     10 juin   7 15:17 libpng.a -> libpng12.a
  0 lrwxrwxrwx 1 fspindle fspindle     11 juin   7 15:17 libpng.so -> libpng12.so
$ rm libpng12.so
$ ln -s ../../../lib/arm-linux-gnueabihf/libpng12.so.0 libpng12.so
\endverbatim

\subsection cross_raspberry_tips_gcc_4_9 Undefined reference to __throw_out_of_range_fmt

This error occurs when cross-compiling for Raspberry Pi 3 Model B.
\verbatim
Linking CXX executable testArray2D
/home/fspindle/sThis is unfortunately due to the OpenCV core library (for Jessie) being built with a newer version of gcc/g++ oft/raspberrypi/rootfs/usr/lib/arm-linux-gnueabihf/libopencv_ts.so.2.4.9: undefined reference to `std::__throw_out_of_range_fmt(char const*, ...)@GLIBCXX_3.4.20'
\endverbatim
This error is due to the fact that OpenCV was built with gcc-4.9 on Raspberry Pi Jessy distro, while the cross-compiler uses gcc-4.8 version.

There exists different work around depending on your use case:
- if you are just interested to build ViSP libraries, a simple workaround is to turn off the build of the tests, demos, tutorials and examples:
\verbatim
$ cd $HOME/soft/visp-crossbuild
$ cmake -DCMAKE_TOOLCHAIN_FILE=../visp/platforms/linux/arm-raspberrypi.toolchain.cmake ../visp -DBUILD_DEMOS=OFF -DBUILD_EXAMPLES=OFF -DBUILD_TESTS=OFF -DBUILD_TUTORIALS=OFF
\endverbatim

- if you are not interested in OpenCV usage on the Raspberry, disable OpenCV:
\verbatim
$ cd $HOME/soft/visp-crossbuild
$ cmake -DCMAKE_TOOLCHAIN_FILE=../visp/platforms/linux/arm-raspberrypi.toolchain.cmake ../visp -DUSE_OPENCV=OFF
\endverbatim

- an other way, that we didn't investigate in depth is to upgrade the toochain to gcc-4.9. Notice that arm-rpi-4.9.3-linux-gnuabihf toolchain in https://github.com/raspberrypi/tools.git doesn't allow cmake to detect all the 3rd parties. During our trial, we succeed to build ViSP, but X11 was not detected. During the configuration cmake only found OpenCV and zbar libraries.

\subsection cross_raspberry_tips_cmake_version CMake 2.8.12 or greater requested

The following error may occur on Raspberry Pi 1 when you are trying to build a project with the resulting cross-build material:
\verbatim
pi@raspberrypi:~ $ cmake .. -DVISP_DIR=/home/pi/visp-crossbuild/lib/cmake/visp
-- The C compiler identification is GNU 4.6.3
-- The CXX compiler identification is GNU 4.6.3
-- Check for working C compiler: /usr/bin/gcc
-- Check for working C compiler: /usr/bin/gcc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++
-- Check for working CXX compiler: /usr/bin/c++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
CMake Error at /home/pi/visp-crossbuild/lib/cmake/visp/VISPModule
s.cmake:156 (message):
  This file relies on consumers using CMake 2.8.12 or greater.
Call Stack (most recent call first):
  /home/pi/visp-crossbuild/lib/cmake/visp/VISPConfig.cmake:170 (i
nclude)
  CMakeLists.txt:5 (find_package)
\endverbatim

The current cmake version is 2.8.9 while 2.8.12 is requested:
\verbatim
pi@raspberrypi:~ $ cmake --version
cmake version 2.8.9
\endverbatim

You definitely need to update cmake version on the Raspberry Pi. To this end download and unpack the lastest CMake release. In our case it was cmake-3.5.2.tar.gz

\verbatim
pi@raspberrypi ~ $ cd soft
pi@raspberrypi ~/soft $ tar xvzf cmake-3.5.2.tar.gz
pi@raspberrypi ~/soft $ cd cmake-3.5.2
\endverbatim

Now to build cmake 3.5.2 run the following (it can take some hours on a Raspberry Pi 1):

\verbatim
pi@raspberrypi ~/soft/cmake-3.5.2 $ ./bootstrap --prefix=/usr
pi@raspberrypi ~/soft/cmake-3.5.2 $ sudo make install
pi@raspberrypi ~/soft/cmake-3.5.2 $ cmake --version
cmake version 3.5.2
\endverbatim

Now you should be able to configure your project and build

\verbatim
pi@raspberrypi:~ $ cmake .. -DVISP_DIR=/home/pi/visp-crossbuild/lib/cmake/visp
pi@raspberrypi:~ $ make
\endverbatim

\section cross_raspberry_next Next tutorial

You are now ready to see the next \ref tutorial-getting-started that will show you how to use ViSP as a 3rd party to build your own project on Raspberry Pi or on any other system. Then if you have a Raspberry Pi camera module, you can also follow the \ref tutorial-tracking-blob especially subsection Tracking form v4l2 live cameras.

*/