0%

how to cross compile opencv on nvidia xaiver arm platform

Guide

systems:

  • ubuntu 16.04
  • gnu gcc/g++ 5.4.0
  • cmake
  • cmake-gui
  • opencv 3.1.0

arm toolchain for cross-compiling

  • arm-linux-gnueabi-gcc 5.4.0
  • arm-linux-gnueabi-g++ 5.4.0

check

1
2
3
4
5
6
7
8
9
10
11
which arm-linux-gnueabi-gcc
/usr/bin/arm-linux-gnueabi-gcc

which arm-linux-gnueabi-g++
/usr/bin/arm-linux-gnueabi-g++

which gcc
/usr/bin/gcc

which g++
/usr/bin/g++

compiling

Difference between Native and Cross compiler

  • A native compiler is one that compiles programs for the same architecture or operating system that it is running on. For instance, a compiler running on an x86 processor and creating x86 binaries.
  • A cross-compiler is one that compiles binaries for architectures other than its own, such as compiling ARM binaries on a Intel’s x86 processor.A “cross compiler” executes in one environment and generates code for another. A “native compiler” generates code for its own execution environment.

2 types:

  • native compiling: compile on x86 for x86 binaries, run on x86
  • cross compiliing: compile on x86 for arm binaries, run on arm

install gnu tools

1
sudo apt-get install gcc g++ 

install arm toolchain

apt-get

Toolchains have a loose name convention like [arch] – [vendor] – [os] – [abi]

  • arch is for architecture: arm, mips, x86, i686…
  • vendor is tool chain supplier: apple,
  • os is for operating system: linux, none (bare metal)
  • abi is for application binary interface convention: eabi, gnueabi, gnueabihf

install toolchains

1
sudo apt-get install gcc-arm-linux-gnueabi g++-arm-linux-gnueabi

install 32-bit libraries

1
sudo apt-get install lib32ncurses5 lib32z1

compile like gnu gcc/g++

1
2
arm-linux-gnueabi-gcc -o hello hello.c
arm-linux-gnueabi-g++ -o hello hello.c

hello only run on arm

source

  • arm-linux-gnueabi-4.5.1.tar.bz2

cmake

1
2
cd opencv-3.1.0
mkdir build && cd build && cmake-gui ..

opencv cross compiling

config
page 1

  • Unix Makefiles
  • Specify options for cross-compiling

page 2

  • operating system: arm-linux
  • c compiler: /usr/bin/arm-linux-gnueabi-gcc
  • c++ compiler:/usr/bin/arm-linux-gnueabi-g++
  • Target ROot: /usr/bin

common cmake options:

CMAKE_INSTALL_PREFIX /usr/local/arm/opencv-arm

Generate and Configure.

1
make -j8

view file

x86-64

file /usr/local/lib/libgtest.so     
/usr/local/lib/libgtest.so: ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=3d9e1f42d0584435a3e6aadb11eabfe620a8d52a, not stripped

arm

file libopencv_core.so 
libopencv_core.so: ELF 32-bit LSB shared object, ARM, EABI5 version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=ce2523820bc6a80972c49e465436d8220abf632c, not stripped

install to arm

copy libs and executables to arm

Reference

History

  • 20190119: created.