# Problem with building OpenCV 4.5.2 + contrib for Java

**URL:** <https://forum.opencv.org/t/problem-with-building-opencv-4-5-2-contrib-for-java/3669>\
**Category:** Android/Java\
**Tags:** build\
**Created:** [June 3, 2021, 5:42pm UTC](https://forum.opencv.org/t/problem-with-building-opencv-4-5-2-contrib-for-java/3669 "2021-06-03T17:42:56Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Skraband](https://avatars.discourse-cdn.com/v4/letter/s/eb8c5e/32.png) [@Skraband](https://forum.opencv.org/u/Skraband)\
**Post date:** [June 3, 2021, 5:42pm UTC](https://forum.opencv.org/t/problem-with-building-opencv-4-5-2-contrib-for-java/3669/1 "2021-06-03T17:42:57Z")

</div>

Hello all,

I am trying to build OpenCV from source with the contrib moduls (especially the tracking one) for quite some time now. I have reade a lot and followed multiple guides yet it didnt work out. I followed this [guide](https://zami0xzami.wordpress.com/2016/03/16/building-java-wrapper-for-opencv/) but wanted to use VS 2019 instead of MinGW. The problem is that the CMake out puts always: Java Wrapper: No . I tried to follow the steps in the guid yet it did not work. Maybe someone can help me. This is the first time that I work with CMake etc., so if you need anything informationwise to help me, let me know.

The complete CMake outpout after adding the contrib/modules path is:

```nohighlight
Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19042.
Detected processor: AMD64
libjpeg-turbo: VERSION = 2.0.6, BUILD = opencv-4.5.2-libjpeg-turbo
Could NOT find OpenJPEG (minimal suitable version: 2.0, recommended version >= 2.3.1). OpenJPEG will be built from sources
OpenJPEG: VERSION = 2.4.0, BUILD = opencv-4.5.2-openjp2-2.4.0
OpenJPEG libraries will be built from sources: libopenjp2 (version "2.4.0")
found Intel IPP (ICV version): 2020.0.0 [2020.0.0 Gold]
at: C:/Users/Fabian/Desktop/Uni/SS21/VRAR/Projekt/Libs/opencv-build/3rdparty/ippicv/ippicv_win/icv
found Intel IPP Integration Wrappers sources: 2020.0.0
at: C:/Users/Fabian/Desktop/Uni/SS21/VRAR/Projekt/Libs/opencv-build/3rdparty/ippicv/ippicv_win/iw
Could not find OpenBLAS include. Turning OpenBLAS_FOUND off
Could not find OpenBLAS lib. Turning OpenBLAS_FOUND off
Could NOT find BLAS (missing: BLAS_LIBRARIES) 
Could NOT find LAPACK (missing: LAPACK_LIBRARIES) 
    Reason given by package: LAPACK could not be found because dependency BLAS could not be found.

Found apache ant: C:/apache-ant-1.9.15/bin/ant.bat (1.9.15)
VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
OpenCV Python: during development append to PYTHONPATH: C:/Users/Fabian/Desktop/Uni/SS21/VRAR/Projekt/Libs/opencv-build/python_loader
Could NOT find PkgConfig (missing: PKG_CONFIG_EXECUTABLE) 
Module opencv_alphamat disabled because the following dependencies are not found: Eigen
Caffe: NO
Protobuf: NO
Glog: NO
freetype2: NO
harfbuzz: NO
Julia not found. Not compiling Julia Bindings. 
Module opencv_ovis disabled because OGRE3D was not found
No preference for use of exported gflags CMake configuration set, and no hints for include/library directories provided. Defaulting to preferring an installed/exported gflags CMake configuration if available.
Failed to find installed gflags CMake configuration, searching for gflags build directories exported with CMake.
Failed to find gflags - Failed to find an installed/exported CMake configuration for gflags, will perform search for installed gflags components.
Failed to find gflags - Could not find gflags include directory, set GFLAGS_INCLUDE_DIR to directory containing gflags/gflags.h
Failed to find glog - Could not find glog include directory, set GLOG_INCLUDE_DIR to directory containing glog/logging.h
Module opencv_sfm disabled because the following dependencies are not found: Eigen Glog/Gflags
Tesseract: NO
Processing WORLD modules...
    module opencv_core...
Allocator metrics storage type: 'long long'
    module opencv_flann...
    module opencv_imgproc...
    module opencv_intensity_transform...
    module opencv_ml...
    module opencv_phase_unwrapping...
    module opencv_photo...
    module opencv_plot...
    module opencv_quality...
    module opencv_reg...
    module opencv_surface_matching...
    module opencv_xphoto...
    module opencv_dnn...
Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': C:/Users/Fabian/Desktop/Uni/SS21/VRAR/Projekt/Libs/opencv-4.5.2/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
opencv_dnn: filter out cuda4dnn source code
    module opencv_dnn_superres...
    module opencv_features2d...
    module opencv_fuzzy...
    module opencv_hfs...
    module opencv_imgcodecs...
    module opencv_line_descriptor...
    module opencv_saliency...
    module opencv_text...
    module opencv_videoio...
    module opencv_wechat_qrcode...
    module opencv_calib3d...
    module opencv_datasets...
    module opencv_highgui...
    module opencv_mcc...
    module opencv_objdetect...
    module opencv_rapid...
    module opencv_rgbd...
rgbd: Eigen support is disabled. Eigen is Required for Posegraph optimization
    module opencv_shape...
    module opencv_structured_light...
    module opencv_video...
    module opencv_videostab...
    module opencv_xfeatures2d...
    module opencv_ximgproc...
    module opencv_xobjdetect...
    module opencv_aruco...
    module opencv_bgsegm...
    module opencv_bioinspired...
    module opencv_ccalib...
    module opencv_dnn_objdetect...
    module opencv_dpm...
    module opencv_face...
    module opencv_gapi...
    module opencv_optflow...
    module opencv_stitching...
    module opencv_superres...
    module opencv_tracking...
    module opencv_stereo...
Processing WORLD modules... DONE

General configuration for OpenCV 4.5.2 =====================================
  Version control: unknown

  Extra modules:
    Location (extra): C:/Users/Fabian/Desktop/Uni/SS21/VRAR/Projekt/Libs/opencv_contrib-4.5.2/modules
    Version control (extra): unknown

  Platform:
    Timestamp: 2021-06-03T17:25:13Z
    Host: Windows 10.0.19042 AMD64
    CMake: 3.20.3
    CMake generator: Visual Studio 16 2019
    CMake build tool: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe
    MSVC: 1929
    Configuration: Debug Release

  CPU/HW features:
    Baseline: SSE SSE2 SSE3
      requested: SSE3
    Dispatched code generation: SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
      requested: SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
      SSE4_1 (17 files): + SSSE3 SSE4_1
      SSE4_2 (2 files): + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (1 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (5 files): + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (31 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
      AVX512_SKX (7 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX

  C/C++:
    Built as dynamic libs?: NO
    C++ standard: 11
    C++ Compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x64/cl.exe (ver 19.29.30037.0)
    C++ flags (Release): /DWIN32 /D_WINDOWS /W4 /GR /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP /MT /O2 /Ob2 /DNDEBUG 
    C++ flags (Debug): /DWIN32 /D_WINDOWS /W4 /GR /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP /MTd /Zi /Ob0 /Od /RTC1 
    C Compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30037/bin/Hostx64/x64/cl.exe
    C flags (Release): /DWIN32 /D_WINDOWS /W3 /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /MP /MT /O2 /Ob2 /DNDEBUG 
    C flags (Debug): /DWIN32 /D_WINDOWS /W3 /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi /fp:precise /MP /MTd /Zi /Ob0 /Od /RTC1 
    Linker flags (Release): /machine:x64 /NODEFAULTLIB:atlthunk.lib /INCREMENTAL:NO /NODEFAULTLIB:libcmtd.lib /NODEFAULTLIB:libcpmtd.lib /NODEFAULTLIB:msvcrtd.lib
    Linker flags (Debug): /machine:x64 /NODEFAULTLIB:atlthunk.lib /debug /INCREMENTAL /NODEFAULTLIB:libcmt.lib /NODEFAULTLIB:libcpmt.lib /NODEFAULTLIB:msvcrt.lib
    ccache: NO
    Precompiled headers: NO
    Extra dependencies: comctl32 gdi32 ole32 setupapi wsock32 ws2_32
    3rdparty dependencies: libprotobuf libjpeg-turbo libwebp libpng libtiff libopenjp2 IlmImf zlib ittnotify quirc ade ippiw ippicv

  OpenCV modules:
    To be built: aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot quality rapid reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode world xfeatures2d ximgproc xobjdetect xphoto
    Disabled: -
    Disabled by dependency: -
    Unavailable: alphamat cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv freetype hdf java julia matlab ovis python2 python3 sfm viz
    Applications: tests perf_tests apps
    Documentation: NO
    Non-free algorithms: NO

  Windows RT support: NO

  GUI: 
    Win32 UI: YES
    VTK support: NO

  Media I/O: 
    ZLib: build (ver 1.2.11)
    JPEG: build-libjpeg-turbo (ver 2.0.6-62)
    WEBP: build (ver encoder: 0x020f)
    PNG: build (ver 1.6.37)
    TIFF: build (ver 42 - 4.2.0)
    JPEG 2000: build (ver 2.4.0)
    OpenEXR: build (ver 2.3.0)
    HDR: YES
    SUNRASTER: YES
    PXM: YES
    PFM: YES

  Video I/O:
    DC1394: NO
    FFMPEG: YES (prebuilt binaries)
      avcodec: YES (58.91.100)
      avformat: YES (58.45.100)
      avutil: YES (56.51.100)
      swscale: YES (5.7.100)
      avresample: YES (4.0.0)
    GStreamer: NO
    DirectShow: YES
    Media Foundation: YES
      DXVA: YES

  Parallel framework: Concurrency

  Trace: YES (with Intel ITT)

  Other third-party libraries:
    Intel IPP: 2020.0.0 Gold [2020.0.0]
           at: C:/Users/Fabian/Desktop/Uni/SS21/VRAR/Projekt/Libs/opencv-build/3rdparty/ippicv/ippicv_win/icv
    Intel IPP IW: sources (2020.0.0)
              at: C:/Users/Fabian/Desktop/Uni/SS21/VRAR/Projekt/Libs/opencv-build/3rdparty/ippicv/ippicv_win/iw
    Lapack: NO
    Eigen: NO
    Custom HAL: NO
    Protobuf: build (3.5.1)

  OpenCL: YES (NVD3D11)
    Include path: C:/Users/Fabian/Desktop/Uni/SS21/VRAR/Projekt/Libs/opencv-4.5.2/3rdparty/include/opencl/1.2
    Link libraries: Dynamic load

  Python (for build): C:/Python27/python2.exe

  Java: export all functions
    ant: C:/apache-ant-1.9.15/bin/ant.bat (ver 1.9.15)
    JNI: C:/Program Files/Java/jdk-16.0.1/include C:/Program Files/Java/jdk-16.0.1/include/win32 C:/Program Files/Java/jdk-16.0.1/include
    Java wrappers: NO
    Java tests: YES

  Install to: C:/Users/Fabian/Desktop/Uni/SS21/VRAR/Projekt/Libs/opencv-build/install
-----------------------------------------------------------------

Configuring done

```

I have installed Pythen 2.7 as well as 3.9 and checked their paths. The path for Ant and my Java JDK are also correct as far as i can tell.

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [June 3, 2021, 6:20pm UTC](https://forum.opencv.org/t/problem-with-building-opencv-4-5-2-contrib-for-java/3669/3 "2021-06-03T18:20:08Z")

</div>

I believe you can force this by setting `HAVE_opencv_java` according to [OpenCV: OpenCV configuration options reference](https://docs.opencv.org/master/db/d05/tutorial_config_reference.html)

---

<div class="post-metadata">

**Author:** ![Skraband](https://avatars.discourse-cdn.com/v4/letter/s/eb8c5e/32.png) [@Skraband](https://forum.opencv.org/u/Skraband)\
**Post date:** [June 3, 2021, 6:29pm UTC](https://forum.opencv.org/t/problem-with-building-opencv-4-5-2-contrib-for-java/3669/4 "2021-06-03T18:29:12Z")

</div>

Yes. Both BUILD\_JAVA and the bindings Generator are enabled. Also “Build\_shared\_libs” is disabled.

In the build folder is a subfolder called “java\_test” and in modules there are two folders called “java” and “java\_bindings\_generator”.

---

<div class="post-metadata">

**Author:** ![Skraband](https://avatars.discourse-cdn.com/v4/letter/s/eb8c5e/32.png) [@Skraband](https://forum.opencv.org/u/Skraband)\
**Post date:** [June 3, 2021, 6:59pm UTC](https://forum.opencv.org/t/problem-with-building-opencv-4-5-2-contrib-for-java/3669/5 "2021-06-03T18:59:40Z")

</div>

Sadly there is no HAVE\_opencv\_java displayed in CMake GUI. But i turned of “BUILD\_opencv\_world” and now CMake displayes “Java wrappers: yes”.

But as soon as i try to build ALL\_BUILD in VS2019 i recieve some error massages.

| Schweregrad | Code | Beschreibung | Projekt | Datei | Zeile | Unterdrückungszustand |
| --- | --- | --- | --- | --- | --- | --- |
| Fehler | MSB8066 | Der benutzerdefinierte Build für “C:\Users\Fabian\Desktop\Uni\SS21\VRAR\Projekt\Libs\opencv-build\CMakeFiles\d7c1b56a3f973ef15a95cd40cc220ac3\opencv\_java\_jar.rule;C:\Users\Fabian\Desktop\Uni\SS21\VRAR\Projekt\Libs\opencv-build\CMakeFiles\d47bc18bbfe91e621ac8e17f92608f6e\opencv\_java\_jar.rule” wurde mit dem Code 1 beendet. | opencv\_java\_jar | C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets | 241 | |
| Fehler | C2660 | “cv::flann::Index::knnSearch”: Funktion akzeptiert keine 3 Argumente (Quelldatei wird kompiliert C:\Users\Fabian\Desktop\Uni\SS21\VRAR\Projekt\Libs\opencv-4.5.2\modules\java\generator\src\cpp\opencv\_java.cpp) | opencv\_java | C:\Users\Fabian\Desktop\Uni\SS21\VRAR\Projekt\Libs\opencv-build\modules\java\_bindings\_generator\gen\cpp\flann.inl.hpp | 115 | |
| Fehler | C2660 | “cv::flann::Index::radiusSearch”: Funktion akzeptiert keine 4 Argumente (Quelldatei wird kompiliert C:\Users\Fabian\Desktop\Uni\SS21\VRAR\Projekt\Libs\opencv-4.5.2\modules\java\generator\src\cpp\opencv\_java.cpp) | opencv\_java | C:\Users\Fabian\Desktop\Uni\SS21\VRAR\Projekt\Libs\opencv-build\modules\java\_bindings\_generator\gen\cpp\flann.inl.hpp | 166 | |
| Fehler | C2668 | “cv::GComputation::compileStreaming”: Mehrdeutiger Aufruf einer überladenen Funktion (Quelldatei wird kompiliert C:\Users\Fabian\Desktop\Uni\SS21\VRAR\Projekt\Libs\opencv-4.5.2\modules\java\generator\src\cpp\opencv\_java.cpp) | opencv\_java | C:\Users\Fabian\Desktop\Uni\SS21\VRAR\Projekt\Libs\opencv-build\modules\java\_bindings\_generator\gen\cpp\gapi.inl.hpp | 178 | |
| Fehler | C2664 | “void cv::detail::focalsFromHomography(const cv::Mat &,double &,double &,bool &,bool &)” : Konvertierung von Argument 4 von “bool” in “bool &” nicht möglich (Quelldatei wird kompiliert C:\Users\Fabian\Desktop\Uni\SS21\VRAR\Projekt\Libs\opencv-4.5.2\modules\java\generator\src\cpp\opencv\_java.cpp) | opencv\_java | C:\Users\Fabian\Desktop\Uni\SS21\VRAR\Projekt\Libs\opencv-build\modules\java\_bindings\_generator\gen\cpp\stitching.inl.hpp | 757 | |
| Fehler | C2352 | “cv::detail::FeaturesMatcher::operator ()”: Unzulässiger Aufruf einer nicht statischen Memberfunktion (Quelldatei wird kompiliert C:\Users\Fabian\Desktop\Uni\SS21\VRAR\Projekt\Libs\opencv-4.5.2\modules\java\generator\src\cpp\opencv\_java.cpp) | opencv\_java | C:\Users\Fabian\Desktop\Uni\SS21\VRAR\Projekt\Libs\opencv-build\modules\java\_bindings\_generator\gen\cpp\stitching.inl.hpp | 903 | |
| Fehler | MSB8066 | Der benutzerdefinierte Build für “C:\Users\Fabian\Desktop\Uni\SS21\VRAR\Projekt\Libs\opencv-build\CMakeFiles\fc14518274f4b25f2ae8c3352bc9db08\opencv-452.jar.rule;C:\Users\Fabian\Desktop\Uni\SS21\VRAR\Projekt\Libs\opencv-build\CMakeFiles\cc0c96cc0c78ac242855082ed816fe54\build.xml.rule;C:\Users\Fabian\Desktop\Uni\SS21\VRAR\Projekt\Libs\opencv-build\CMakeFiles\e7566522d6995bc21b289513e5c066f0\junit-4.11.jar.rule;C:\Users\Fabian\Desktop\Uni\SS21\VRAR\Projekt\Libs\opencv-build\CMakeFiles\12f24d42752f18f701e779a0623a489c\OpenCVTestCase.java.rule;C:\Users\Fabian\Desktop\Uni\SS21\VRAR\Projekt\Libs\opencv-build\CMakeFiles\12f24d42752f18f701e779a0623a489c\OpenCVTestRunner.java.rule;C:\Users\Fabian\Desktop\Uni\SS21\VRAR\Projekt\Libs\opencv-build\CMakeFiles\30325c1efe71e29f032936ff6085f125\opencv-test.jar.rule;C:\Users\Fabian\Desktop\Uni\SS21\VRAR\Projekt\Libs\opencv-build\CMakeFiles\64fcd4826f54cfa07c6808536ed3bee0\opencv\_test\_java.rule” wurde mit dem Code 1 beendet. | opencv\_test\_java | C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Microsoft\VC\v160\Microsoft.CppCommon.targets | 241 | |

---

<div class="post-metadata">

**Author:** ![crackwitz](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/crackwitz/32/14_2.png) [@crackwitz](https://forum.opencv.org/u/crackwitz)\
**Post date:** [June 3, 2021, 7:08pm UTC](https://forum.opencv.org/t/problem-with-building-opencv-4-5-2-contrib-for-java/3669/6 "2021-06-03T19:08:53Z")

</div>

possibly related to [Error compiling OpenCV with contrib module rgbd and java wrapper · Issue #2700 · opencv/opencv\_contrib · GitHub](https://github.com/opencv/opencv_contrib/issues/2700) (but that’s OSX and android)

you could try disabling the bindings generator flag.

as for `HAVE_opencv_java`, if you want to try that (while building world instead of individual module libs), you’d create that value in opencv-gui because it doesn’t exist yet.

---

<div class="post-metadata">

**Author:** ![Skraband](https://avatars.discourse-cdn.com/v4/letter/s/eb8c5e/32.png) [@Skraband](https://forum.opencv.org/u/Skraband)\
**Post date:** [June 5, 2021, 5:37pm UTC](https://forum.opencv.org/t/problem-with-building-opencv-4-5-2-contrib-for-java/3669/7 "2021-06-05T17:37:48Z")

</div>

I solved the Problem. What did the trick for me, was not trying to build opencv\_world, having build-shared\_libs disabled and also disable Build\_fat\_Java\_libs

---

<div class="post-metadata">

**Author:** ![floriantr](https://avatars.discourse-cdn.com/v4/letter/f/97f17d/32.png) [@floriantr](https://forum.opencv.org/u/floriantr)\
**Post date:** [July 31, 2021, 7:03pm UTC](https://forum.opencv.org/t/problem-with-building-opencv-4-5-2-contrib-for-java/3669/8 "2021-07-31T19:03:46Z")

</div>

Hello Skraband, I am also new to CMake and I have a similar problem with installing contrib for Java. How did you solve it? Setting Build\_opencv\_world true, build\_shared\_libs false and build \_fat\_java\_libs false? I already tried several constellations but none of them worked. I only get a opencv\_java453.dll but no .jar file.

---

<div class="post-metadata">

**Author:** ![Sai\_Dedeep](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opencv.org/sai_dedeep/32/6114_2.png) [@Sai\_Dedeep](https://forum.opencv.org/u/Sai_Dedeep)\
**Post date:** [September 21, 2022, 3:28pm UTC](https://forum.opencv.org/t/problem-with-building-opencv-4-5-2-contrib-for-java/3669/9 "2022-09-21T15:28:09Z")

</div>

hey were you able to solve your issue?
