arm_crosscompile_with_cmake.markdown 3.7 KB
Newer Older
1 2 3
Cross compilation for ARM based Linux systems {#tutorial_arm_crosscompile_with_cmake}
=============================================

4 5 6 7
@prev_tutorial{tutorial_ios_install}
@next_tutorial{tutorial_building_tegra_cuda}


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
This steps are tested on Ubuntu Linux 12.04, but should work for other Linux distributions. I case
of other distributions package names and names of cross compilation tools may differ. There are
several popular EABI versions that are used on ARM platform. This tutorial is written for *gnueabi*
and *gnueabihf*, but other variants should work with minimal changes.

Prerequisites
-------------

-   Host computer with Linux;
-   Git;
-   CMake 2.6 or higher;
-   Cross compilation tools for ARM: gcc, libstc++, etc. Depending on target platform you need to
    choose *gnueabi* or *gnueabihf* tools. Install command for *gnueabi*:
    @code{.bash}
    sudo apt-get install gcc-arm-linux-gnueabi
    @endcode
    Install command for *gnueabihf*:
    @code{.bash}
    sudo apt-get install gcc-arm-linux-gnueabihf
    @endcode
-   pkgconfig;
-   Python 2.6 for host system;
-   [optional] ffmpeg or libav development packages for armeabi(hf): libavcodec-dev,
    libavformat-dev, libswscale-dev;
-   [optional] GTK+2.x or higher, including headers (libgtk2.0-dev) for armeabi(hf);
-   [optional] libdc1394 2.x;
-   [optional] libjpeg-dev, libpng-dev, libtiff-dev, libjasper-dev for armeabi(hf).

Getting OpenCV Source Code
--------------------------

You can use the latest stable OpenCV version available in *sourceforge* or you can grab the latest
40
snapshot from our [Git repository](https://github.com/opencv/opencv.git).
41 42 43 44 45 46 47 48

### Getting the Latest Stable OpenCV Version

-   Go to our [page on Sourceforge](http://sourceforge.net/projects/opencvlibrary);
-   Download the source tarball and unpack it.

### Getting the Cutting-edge OpenCV from the Git Repository

49
Launch Git client and clone [OpenCV repository](http://github.com/opencv/opencv)
50 51 52 53

In Linux it can be achieved with the following command in Terminal:
@code{.bash}
cd ~/<my_working _directory>
54
git clone https://github.com/opencv/opencv.git
55
@endcode
M
Maksim Shabunin 已提交
56

57 58 59
Building OpenCV
---------------

M
Maksim Shabunin 已提交
60
-#  Create a build directory, make it current and run the following command:
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
    @code{.bash}
    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>
    @endcode
    Toolchain uses *gnueabihf* EABI convention by default. Add -DSOFTFP=ON cmake argument to switch
    on softfp compiler.
    @code{.bash}
    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>
    @endcode
    For example:
    @code{.bash}
    cd ~/opencv/platforms/linux
    mkdir -p build_hardfp
    cd build_hardfp

    cmake -DCMAKE_TOOLCHAIN_FILE=../arm-gnueabi.toolchain.cmake ../../..
    @endcode
M
Maksim Shabunin 已提交
77 78

-#  Run make in build (\<cmake_binary_dir\>) directory:
79 80 81
    @code{.bash}
    make
    @endcode
M
Maksim Shabunin 已提交
82

83
@note
M
Maksim Shabunin 已提交
84 85
Optionally you can strip symbols info from the created library via install/strip make target.
This option produces smaller binary (\~ twice smaller) but makes further debugging harder.
86 87 88 89 90 91 92 93 94 95

### Enable hardware optimizations

Depending on target platform architecture different instruction sets can be used. By default
compiler generates code for armv5l without VFPv3 and NEON extensions. Add -DENABLE_VFPV3=ON to
cmake command line to enable code generation for VFPv3 and -DENABLE_NEON=ON for using NEON SIMD
extensions.

TBB is supported on multi core ARM SoCs also. Add -DWITH_TBB=ON and -DBUILD_TBB=ON to enable it.
Cmake scripts download TBB sources from official project site
M
Maksim Shabunin 已提交
96
<http://threadingbuildingblocks.org/> and build it.