从头开发一个自己的JavaCPP presets

  |   0 评论   |   204 浏览

背景

环境准备

Linux Docker

本文以CentOS环境下,制作Linux环境下的JavaCPP presets为例。其它平台的,见本文末尾的参考[1]。

安装docker

$ sudo yum install docker

修改服务配置

$ sudo systemctl stop firewalld
$ sudo systemctl start docker

启动docker

$ sudo docker run --privileged -it centos:7 /bin/bash

结果

Unable to find image 'centos:7' locally
Trying to pull repository docker.io/library/centos ...
7: Pulling from docker.io/library/centos
90c48ff53512: Pull complete
Digest: sha256:8d487d68857f5bc9595793279b33d082b03713341ddec91054382641d14db861
Status: Downloaded newer image for docker.io/centos:7
[root@48d5a09c8de3 /]# 

在容器中安装包

# yum install epel-release
# yum install ccache clang gcc-c++ gcc-gfortran java-devel ant maven python python36-devel python36-setuptools numpy swig git file which wget unzip tar bzip2 gzip xz patch autoconf-archive automake make cmake3 libtool perl nasm yasm alsa-lib-devel freeglut-devel gtk2-devel libusb-devel libusb1-devel zlib-devel SDL-devel libva-devel python36-pip
# yum install `rpm -qa | sed s/.x86_64$/.i686/`
  1. 我本地最后一步省略掉了。因为用的不是x86的linux环境。
  2. 第二次用x86的linux环境操作时,先省略掉了最后一步,因为电脑磁盘有限。

准备javacpp 和 javacpp-presets包

要使用相同版本的 javacppjavacpp-presets。可以都使用master版本,也可以使用同一个 ctag 下的版本。

这里我们都取tag下的最新的1.4.4版本,因为 master 编译不过。

同样的,在容器中执行:

# git clone -b 1.4.4 https://github.com/bytedeco/javacpp.git
# git clone -b 1.4.4 https://github.com/bytedeco/javacpp-presets.git
# cd javacpp
# mvn clean install

安装onnx

安装 onnx 只是为了练手。

准备

# yum install python34-pip python36-pip
# cd ../javacpp-presets/ffmpeg
# mvn clean install

结果

[INFO] Installing /root/build/javacpp-presets/onnx/target/onnx.jar to /root/.m2/repository/org/bytedeco/javacpp-presets/onnx/1.3.0-1.4.4/onnx-1.3.0-1.4.4.jar
[INFO] Installing /root/build/javacpp-presets/onnx/pom.xml to /root/.m2/repository/org/bytedeco/javacpp-presets/onnx/1.3.0-1.4.4/onnx-1.3.0-1.4.4.pom
[INFO] Installing /root/build/javacpp-presets/onnx/target/onnx-linux-aarch64.jar to /root/.m2/repository/org/bytedeco/javacpp-presets/onnx/1.3.0-1.4.4/onnx-1.3.0-1.4.4-linux-aarch64.jar
[INFO] Installing /root/build/javacpp-presets/onnx/target/onnx-sources.jar to /root/.m2/repository/org/bytedeco/javacpp-presets/onnx/1.3.0-1.4.4/onnx-1.3.0-1.4.4-sources.jar
[INFO] Installing /root/build/javacpp-presets/onnx/target/onnx-javadoc.jar to /root/.m2/repository/org/bytedeco/javacpp-presets/onnx/1.3.0-1.4.4/onnx-1.3.0-1.4.4-javadoc.jar

安装 cpython

# cd ../cpython
# mvn clean install

结果

[INFO] Installing /root/build/javacpp-presets/cpython/target/cpython.jar to /root/.m2/repository/org/bytedeco/javacpp-presets/cpython/3.6-1.4.4/cpython-3.6-1.4.4.jar
[INFO] Installing /root/build/javacpp-presets/cpython/pom.xml to /root/.m2/repository/org/bytedeco/javacpp-presets/cpython/3.6-1.4.4/cpython-3.6-1.4.4.pom
[INFO] Installing /root/build/javacpp-presets/cpython/target/cpython-linux-aarch64.jar to /root/.m2/repository/org/bytedeco/javacpp-presets/cpython/3.6-1.4.4/cpython-3.6-1.4.4-linux-aarch64.jar
[INFO] Installing /root/build/javacpp-presets/cpython/target/cpython-sources.jar to /root/.m2/repository/org/bytedeco/javacpp-presets/cpython/3.6-1.4.4/cpython-3.6-1.4.4-sources.jar
[INFO] Installing /root/build/javacpp-presets/cpython/target/cpython-javadoc.jar to /root/.m2/repository/org/bytedeco/javacpp-presets/cpython/3.6-1.4.4/cpython-3.6-1.4.4-javadoc.jar

踩坑记录

定制jni so包的编译选项

修改pom.xml,如下文所示,增加compilerOption配置。

      <plugin>
        <groupId>org.bytedeco</groupId>
        <artifactId>javacpp</artifactId>
	    <configuration>
            <compilerOptions>
                <compilerOption>-O0</compilerOption>
                <compilerOption>-g3</compilerOption>
            </compilerOptions>
         </configuration>
      </plugin>

参考

评论

发表评论

validate