Friday, October 14, 2016

Building OpenCV with Java on Linux

This command worked for me:
cmake .. -DJAVA_INCLUDE_PATH=/usr/lib/jvm/java-8-oracle/include/ -DJAVA_INCLUDE_PATH2=/usr/lib/jvm/java-8-oracle/include/linux
It was not necessary to set BUILD_SHARED_LIBS to false as described on That would be rather undesirable to lose the ability to use shared libs just because you also want to use Java!

**HOWEVER**, because BUILD_SHARED_LIBS is set, will have dependencies. It will be necessary to load among others into the JVM at runtime, AND THEN to have see those symbols. This is tricky in Java! If you don't want to go through this pain, you can go and unset BUILD_SHARED_LIBS; I won't judge you.

Essentially, what you need is a way to set RTLD_GLOBAL when loading the library. This can be accomplished using JNA:
 Then you should be able to use OpenCV.