cross compile opencv for nvidia xaiver arm platform

cross compile opencv for 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

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

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

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

install 32-bit libraries

sudo apt-get install lib32ncurses5 lib32z1

compile like gnu gcc/g++

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

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.

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.
坚持技术分享,您的支持将鼓励我继续创作!