Building native libraries not working

asked 2018-04-04 08:12:37 -0600

Jérémy K gravatar image

updated 2018-04-04 08:24:02 -0600

When following the instructions for building native libraries for OpenCV with cmake, I don't get any /libs folder with the .so file and the .jar file isn't generated either.

I'm following these steps:

1. Installing dependencies:

sudo apt-get update && sudo apt-get install oracle-java8-jdk cmake ant
sudo apt-get install build-essential cmake pkg-config libpng12-0 libpng12-dev libpng++-dev libpng3 libpnglite-dev zlib1g-dbg zlib1g zlib1g-dev pngtools  libtiff4 libtiffxx0c2 libtiff-tools libjpeg8 libjpeg8-dev libjpeg8-dbg libjpeg-progs libavcodec-dev   libavformat-dev libgstreamer0.10-0-dbg libgstreamer0.10-0 libgstreamer0.10-dev  libunicap2 libunicap2-dev libdc1394-22-dev libdc1394-22 libdc1394-utils swig libv4l-0 libv4l-dev

2. Adding export paths:

export ANT_HOME=/usr/share/ant/
export PATH=${PATH}:${ANT_HOME}/bin
export JAVA_HOME=/usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/
export PATH=$PATH:$JAVA_HOME/bin

3. Downloading OpenCV:

wget https://github.com/opencv/opencv/archive/3.4.0.zip
mv 3.4.0 opencv.zip
unzip opencv.zip 
cd opencv-3.4.0/

4. Make & Install:

mkdir build
cd build
cmake -D CMAKE_BUILD_TYPE=RELEASE -D WITH_OPENCL=OFF -D BUILD_PERF_TESTS=OFF -D BUILD_SHARED_LIBS=OFF -D JAVA_INCLUDE_PATH=$JAVA_HOME/include -D JAVA_AWT_LIBRARY=$JAVA_HOME/jre/lib/arm/libawt.so -D JAVA_JVM_LIBRARY=$JAVA_HOME/jre/lib/arm/server/libjvm.so -D CMAKE_INSTALL_PREFIX=/usr/local ..
make
make install

I'm running this on a Raspberry Pi. A part of the output of cmake is:

--   OpenCV modules:
--     To be built:                 calib3d core dnn features2d flann highgui imgcodecs imgproc ml objdetect photo python_bindings_generator shape stitching superres ts video videoio videostab
--     Disabled:                    js world
--     Disabled by dependency:      -
--     Unavailable:                 cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev java python2 python3 viz

<-- some other stuff -->

--   Python (for build):            /usr/bin/python2.7
--
--   Java:
--     ant:                         /usr/bin/ant (ver 1.9.4)
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO

which concerns me..

Thanks in advance for your help!

Edit: Also noticed this error in cmake:

-- Could NOT find JNI (missing:  JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
edit retag flag offensive close merge delete

Comments

if at all, you should try with latest opencv, not outdated 3.2.

berak gravatar imageberak ( 2018-04-04 08:21:17 -0600 )edit

Sorry, copy paste error on my side! I did run it on 3.4. I might however have a breakthrough, standby!

Jérémy K gravatar imageJérémy K ( 2018-04-04 08:24:36 -0600 )edit

$JAVA_HOME -- that's the jre, not a jdk, right ? (you need one !)

it did not find the java headers/libs nessecary. as long as cmake says: Java wrappers: NO it'S no use running make. you have to fix this before going on.

also try to use cmake-gui instead of cmake. it's quite good at finding the right things.

last: if you only wanted the java bindings, use: cmake -DBUILD_SHARED_LIBS=OFF , else it will depend on further opencv so's at runtime

berak gravatar imageberak ( 2018-04-04 08:25:35 -0600 )edit

Okay so, I opened this issue because I've been trying to get this working for hours. In the end, I noticed that I had a different JDK (OpenJDK instead of Oracle JDK) which I thought caused the issue. However, after installing the Oracle JDK and changing the paths in the bashrc, it still didn't work. At this point, I was lost and decided to open this issue. I did however forget to source the file so that it's updated, which I now did and changes everything! I am however still having a bug which causes cmake to still try to use the old non-oracle JDK, but trying to fix this now.

Jérémy K gravatar imageJérémy K ( 2018-04-04 08:32:13 -0600 )edit

Thanks for your reply berak! :D I'm nog awaiting the build as said, but you're saying that I better just run cmake -DBUILD_SHARED_LIBS=OFF without all the other options? I indeed only need the native libraries and need them linked to Java..

Jérémy K gravatar imageJérémy K ( 2018-04-04 08:40:21 -0600 )edit

no, not without the other options, ofc.

berak gravatar imageberak ( 2018-04-04 08:42:29 -0600 )edit

Hi Berak, everything goes perfect till one of the latest steps of the make in which I get: Target 'jar' failed with message 'Unable to find a javac compiler; com.sun.tools.javac.Main is not on the classpath. Perhaps JAVA_HOME does not point to the JDK. It is currently set to "/usr/lib/jvm/java-8-openjdk-armhf/jre"'. The path with openjdk is still the old Java path.. Do you know if make gets the path from somwhere else than bashrc?

Jérémy K gravatar imageJérémy K ( 2018-04-04 09:31:59 -0600 )edit

can't you point JAVA_HOME to your jdk ?

(that's how it is here, and on my heroku box (where this runs fine with OpenJDK, btw)

((i'm slightly out of ideas, it's all about something broken, the way you'ver set up your java things. hard to remote-debug from here.))

berak gravatar imageberak ( 2018-04-04 09:38:07 -0600 )edit

JAVA_HOME is pointed to /usr/lib/jvm/jdk-8-oracle-arm32-vfp-hflt/ , isn't this correct?

Jérémy K gravatar imageJérémy K ( 2018-04-04 09:49:09 -0600 )edit