• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1Cross compilation for ARM based Linux systems {#tutorial_arm_crosscompile_with_cmake}
2=============================================
3
4This steps are tested on Ubuntu Linux 12.04, but should work for other Linux distributions. I case
5of other distributions package names and names of cross compilation tools may differ. There are
6several popular EABI versions that are used on ARM platform. This tutorial is written for *gnueabi*
7and *gnueabihf*, but other variants should work with minimal changes.
8
9Prerequisites
10-------------
11
12-   Host computer with Linux;
13-   Git;
14-   CMake 2.6 or higher;
15-   Cross compilation tools for ARM: gcc, libstc++, etc. Depending on target platform you need to
16    choose *gnueabi* or *gnueabihf* tools. Install command for *gnueabi*:
17    @code{.bash}
18    sudo apt-get install gcc-arm-linux-gnueabi
19    @endcode
20    Install command for *gnueabihf*:
21    @code{.bash}
22    sudo apt-get install gcc-arm-linux-gnueabihf
23    @endcode
24-   pkgconfig;
25-   Python 2.6 for host system;
26-   [optional] ffmpeg or libav development packages for armeabi(hf): libavcodec-dev,
27    libavformat-dev, libswscale-dev;
28-   [optional] GTK+2.x or higher, including headers (libgtk2.0-dev) for armeabi(hf);
29-   [optional] libdc1394 2.x;
30-   [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev for armeabi(hf).
31
32Getting OpenCV Source Code
33--------------------------
34
35You can use the latest stable OpenCV version available in *sourceforge* or you can grab the latest
36snapshot from our [Git repository](https://github.com/Itseez/opencv.git).
37
38### Getting the Latest Stable OpenCV Version
39
40-   Go to our [page on Sourceforge](http://sourceforge.net/projects/opencvlibrary);
41-   Download the source tarball and unpack it.
42
43### Getting the Cutting-edge OpenCV from the Git Repository
44
45Launch Git client and clone [OpenCV repository](http://github.com/itseez/opencv)
46
47In Linux it can be achieved with the following command in Terminal:
48@code{.bash}
49cd ~/<my_working _directory>
50git clone https://github.com/Itseez/opencv.git
51@endcode
52
53Building OpenCV
54---------------
55
56-#  Create a build directory, make it current and run the following command:
57    @code{.bash}
58    cmake [<some optional parameters>] -DCMAKE_TOOLCHAIN_FILE=<path to the OpenCV source directory>/platforms/linux/arm-gnueabi.toolchain.cmake <path to the OpenCV source directory>
59    @endcode
60    Toolchain uses *gnueabihf* EABI convention by default. Add -DSOFTFP=ON cmake argument to switch
61    on softfp compiler.
62    @code{.bash}
63    cmake [<some optional parameters>] -DSOFTFP=ON -DCMAKE_TOOLCHAIN_FILE=<path to the OpenCV source directory>/platforms/linux/arm-gnueabi.toolchain.cmake <path to the OpenCV source directory>
64    @endcode
65    For example:
66    @code{.bash}
67    cd ~/opencv/platforms/linux
68    mkdir -p build_hardfp
69    cd build_hardfp
70
71    cmake -DCMAKE_TOOLCHAIN_FILE=../arm-gnueabi.toolchain.cmake ../../..
72    @endcode
73
74-#  Run make in build (\<cmake_binary_dir\>) directory:
75    @code{.bash}
76    make
77    @endcode
78
79@note
80Optionally you can strip symbols info from the created library via install/strip make target.
81This option produces smaller binary (\~ twice smaller) but makes further debugging harder.
82
83### Enable hardware optimizations
84
85Depending on target platform architecture different instruction sets can be used. By default
86compiler generates code for armv5l without VFPv3 and NEON extensions. Add -DENABLE_VFPV3=ON to
87cmake command line to enable code generation for VFPv3 and -DENABLE_NEON=ON for using NEON SIMD
88extensions.
89
90TBB is supported on multi core ARM SoCs also. Add -DWITH_TBB=ON and -DBUILD_TBB=ON to enable it.
91Cmake scripts download TBB sources from official project site
92<http://threadingbuildingblocks.org/> and build it.
93