Skip to content
Samuel Audet edited this page Jan 17, 2018 · 36 revisions

Introduction

This page contains a description of the environments that are used to build the JavaCPP Presets for Android (ARM and x86), Linux (x86 and x86_64), Linux (ARM), Mac OS X (x86_64), and Windows (x86 and x86_64). We also explain our choices given the requirements and provide some recommendations. Furthermore, JavaCPP is by no means limited to these platforms, so if you happen to know how to set up an environment for other platforms, by all means, please do add that information to this page to share with others. Thank you!

Prerequisites for all platforms

The build process for the modules of javacpp-presets usually depends on the same version of the javacpp module. To insure that you have the latest matching version of both, please execute the following before starting the build in the javacpp-presets directory:

$ git clone https://github.com/bytedeco/javacpp.git --branch <tag>
$ git clone https://github.com/bytedeco/javacpp-presets.git --branch <tag>
$ cd javacpp
$ mvn clean install

For the latest tag please check https://github.com/bytedeco/javacpp-presets/tags or use "master".

Android (ARM and x86)

To produce native libraries for Android, we basically only need to install the JDK and the NDK, which is available for Linux, Mac OS X, and Windows. However, the build scripts of some libraries only run correctly under Linux, so we recommend using a recent distribution of Linux (such as Fedora or Ubuntu) as build environment for Android.

Preparations

  1. Download the latest version of the NDK, which is r10e at the time of this writing and contains important fixes for OpenMP, among other things. The OpenBLAS preset requires a FORTRAN compiler to build the LAPACK library. Download the gcc-arm-linux-x86_64.tar.bz2 and gcc-x86-linux-x86_64.tar.bz2 toolchains with FORTRAN compiler and follow the instructions from https://github.com/buffer51/android-gfortran to deploy the toolchains into the NDK folder.
  2. Install the NDK under ~/Android/android-ndk, where the build scripts will look for it by default.
  3. Finally, make sure to have installed at least OpenJDK and Maven as per the instructions of your distribution.
  4. Run the "Prerequisites for all platforms" tasks inside the shell.

After which the following commands can be used to start the build inside the javacpp-presets directory:

$ ANDROID_NDK=/path/to/android-ndk/ bash cppbuild.sh -platform android-xxx install
$ mvn clean install -Djavacpp.platform=android-xxx -Djavacpp.platform.root=/path/to/android-ndk/ -Djavacpp.platform.compiler=/path/to/target-g++

where android-xxx is either android-arm or android-x86, and where target-g++ is either arm-linux-androideabi-g++ or i686-linux-android-g++.

Linux (x86 and x86_64)

To produce native libraries that can run on the largest possible number of Linux installations out there, it is recommended to build under CentOS 7. This is because it relies on an old enough version of glibc, which nevertheless works for all the libraries found in the JavaCPP Presets, and since newer versions of glibc are backward compatible, all recent distributions of Linux should support the binaries generated. We do not actually need to install CentOS 7 though. Pretty much any recent distribution of Linux comes with a package for Docker. It is also possible to map existing directories, for example /usr/local/lib/bazel and /usr/local/cuda as shown in the steps below, to reuse an existing Bazel or CUDA installation as well as any other set of files for the purpose of the build.

Preparations

  1. Install Docker under, for example, Fedora and Ubuntu, respectively:

    $ sudo yum install docker
    $ sudo apt-get install docker.io
  2. When using SELinux, it might also be necessary to disable temporarily the firewall, for example:

    $ sudo systemctl stop firewalld
    $ sudo systemctl start docker
    
  3. Start the container for CentOS 7 (the command might be docker.io instead of docker):

    $ sudo docker run --privileged -it -v /usr/local/lib/bazel:/usr/local/lib/bazel -v /usr/local/cuda:/usr/local/cuda centos:7 /bin/bash
  4. Finally, inside the container, we need to install a bunch of things:

    $ ln -s /usr/local/lib/bazel/bin/bazel /usr/local/bin/bazel
    $ yum install epel-release
    $ yum install clang gcc-c++ gcc-gfortran java-devel maven python numpy swig git file which wget unzip tar bzip2 gzip xz patch automake make cmake3 libtool perl nasm yasm alsa-lib-devel freeglut-devel glfw-devel gtk2-devel libusb-devel libusb1-devel zlib-devel SDL-devel
    $ yum install `rpm -qa | sed s/.x86_64$/.i686/`
  5. Run the "Prerequisites for all platforms" tasks inside the shell.

After which the following commands can be used to start the build inside the javacpp-presets directory:

$ bash cppbuild.sh -platform linux-xxx install
$ mvn clean install -Djavacpp.platform=linux-xxx

where linux-xxx is either linux-x86 or linux-x86_64.

Linux (ARM)

There are a growing number of arm platforms running Linux, though testing of this build has mainly focussed on the Pi family of products. It's recommended to use the cross compiling approach, this is what happens automatically via Travis for every pull for testing, and for commits to provide up to date snapshots. If you just want the latest functionality, it's worth using these snapshot builds. However, it's possible to build natively on the target device too, both approaches are described here.

Cross compile

For an Ubuntu host, the following steps should work - but you may need to tune depending on your existing host setup, OS version, package conflicts etc. Alternatively you could build in a clean docker container.

$ sudo dpkg --add-architecture i386
$ sudo apt-get update
$ sudo apt-get -y install libc6:i386 libncurses5:i386 libstdc++6:i386 lib32z1
$ sudo apt-get -y install clang git file  wget unzip tar bzip2 gzip  patch automake libtool perl nasm yasm libasound2-dev freeglut3-dev libglfw3-dev libgtk2.0-dev libusb-dev zlib1g
$ git -C ~/ clone https://github.com/raspberrypi/tools
$ export PATH=$PATH:~/tools/arm-bcm2708/gcc-linaro-arm-linux-gnueabihf-raspbian/bin
$ git clone https://github.com/bytedeco/javacpp-presets.git
$ cd javacpp-presets
$ mvn install -U -Djavacpp.platform=linux-armhf -Djavacpp.platform.compiler=arm-linux-gnueabihf-g++

Native compile

You can compile directly on the device as well, for the Pi series this can be very time consuming (OpenCV takes approx 2h on a Pi3, ffmpeg around 1h, etc). You'll also need to increase your swap size for packages such as OpenBLAS - which can be detrimental to the SD card.

Basic steps required here are:

$ sudo apt-get update
$ sudo apt-get install clang maven python swig git file wget unzip tar bzip2 gzip patch automake make cmake libtool perl nasm yasm gfortran
$ git clone https://github.com/bytedeco/javacpp-presets.git
$ cd javacpp-presets
$ mvn install -Djavacpp.platform=linux-armhf -Dmaven.javadoc.skip=true

Platform specifics

If you want to try alternative flags, you need to modify in javacpp, ./src/main/resources/org/bytedeco/javacpp/properties/linux-armhf.properties and then in javacpp-presets any project cppbuild.sh file where you want to update too (e.g. ./opencv/cppbuild.sh linux-armhf section). For newer Pis on arm7 it does look like there are potential performance gains in armv7 and neon flags, and using a newer compiler rather than the bcm2708 build used here may further improve things (some earlier builds specific for armv7 did look faster). Also if you are using onboard picam devices, make sure you load the module with "modprobe bcm2835-v4l2 max_video_width=2592 max_video_height=1944" - this way if you test just using OpenCV or FFMPEG grabber you should get at least 30fps as a start point. The more computation you then do on each frame, the more this will drop.

Mac OS X (x86_64)

OS X Mavericks (10.9) is the first version of Mac OS X to support C++11 fully and properly, so to preserve your sanity, we do not recommend trying to build or use the JavaCPP Presets on any older versions of Mac OS X.

Preparations

  1. Install Xcode and Homebrew

  2. Ensure the command line tools for Xcode are installed

    $ xcode-select --install
  3. Run the following commands to install the JDK, among other things Apple left out of Xcode:

    $ brew install caskroom/cask/brew-cask
    $ brew cask install cuda java
    $ brew install gcc5 swig automake bazel cmake libtool libusb maven nasm yasm xz pkg-config sdl
  4. Run the "Prerequisites for all platforms" tasks inside the shell.

After which the following commands can be used to start the build inside the javacpp-presets directory:

$ bash cppbuild.sh install
$ mvn clean install

Windows (x86 and x86_64)

Visual Studio Community 2013 is the first free version to have been decently bundled with support for C++11, OpenMP, the Windows SDK, and everything else from Microsoft, but we recommend installing version 2015 of Visual Studio since it is needed by some libraries, which consequently requires Windows 7. Still, to run the bash scripts and compile some things that the Microsoft C/C++ Compiler does not support, we need to install manually a few other things.

Preparations

  1. Install the Java SE Development Kit, Maven, MSYS2, Visual Studio Community 2015, Windows SDK, and CUDA.

  2. Under an "MSYS2 Shell", run:

    $ pacman -S base-devel tar patch make git unzip zip nasm yasm pkg-config mingw-w64-x86_64-cmake mingw-w64-x86_64-gcc mingw-w64-i686-gcc mingw-w64-x86_64-gcc-fortran mingw-w64-i686-gcc-fortran mingw-w64-x86_64-libwinpthread-git mingw-w64-i686-libwinpthread-git mingw-w64-x86_64-SDL mingw-w64-i686-SDL
  3. From the "Visual Studio 2015" folder found inside the Start menu, open:

    • "VS2015 x86 Native Tools Command Prompt" and run c:\msys64\mingw32.exe inside
    • "VS2015 x64 Native Tools Command Prompt" and run c:\msys64\mingw64.exe inside
    • Making sure the MSYS2_PATH_TYPE=inherit line is not commented out in mingw64.ini or mingw32.ini.
  4. Run the "Prerequisites for all platforms" tasks inside the shell.

Afterwards the following commands can be used to start the build inside the javacpp-presets directory:

$ bash cppbuild.sh -platform windows-xxx install
$ mvn clean install -Djavacpp.platform=windows-xxx

where windows-xxx is either windows-x86 or windows-x86_64. Run the builds for windows-x86 inside the "MINGW32" window, and the ones for windows-x86_64 in the "MINGW64" one.

∗ More detailed instructions available at Building-on-Windows#installation-recipe-for-visual-studiuo-2015-and-windows-10


Thank you very much for your interest in this project, and please feel free to post your questions on the mailing list and open new issues to communicate your suggestions.