UnsatisfiedLinkError: opencv_java460.dll: Can't find dependent libraries

I am trying to build openCV 460 from source with cuda support for java. I’ve run thru the build process a million times in the past week all but 1 with negative results and have run out of bright ideas on how to ever get this running so I can start the intended development process;

  • I’m building on MS Windows 10
  • I’m configuring from CMake gui
  • I’m building from visual studio 2022
  • I’ve run into issues while configuring from a FAT32 partition where certain modules would not download, this seemed to be solved by building from an NTFS volume
  • I’ve configured and build with about 2 different jdk’s (11 coretto from intelij / 11 oracle from intelij / 11 coretto from windows / 11 oracle from windows, all to no avail.
  • jar’s and dll’s seem to have been build successfully no errors during configure or build stage.
  • building cuda arch 8.6 only for an RTX3060
  • cuda 11.7 installed as per manual, successfully detected during configure
  • latest cudnn installed as per manual. successfully detected during configure
  • building without tests
  • building without examples

The error I am observing is;

"C:\Program Files\Java\jdk-11.0.16\bin\java.exe" "-Djava.library.path=C:\Program Files\opencv\java" "-javaagent:C:\Program Files\JetBrains\IntelliJ IDEA 2022.2.2\lib\idea_rt.jar=50120:C:\Program Files\JetBrains\IntelliJ IDEA 2022.2.2\bin" -Dfile.encoding=UTF-8 -classpath "J:\mmj-jarvis\ai\target\classes;C:\Users\tony.wijnhard\.m2\repository\net\java\dev\jna\jna-jpms\5.12.1\jna-jpms-5.12.1.jar;C:\Users\tony.wijnhard\.m2\repository\net\java\dev\jna\jna-platform-jpms\5.12.1\jna-platform-jpms-5.12.1.jar;C:\Users\tony.wijnhard\.m2\repository\net\java\dev\jna\jna\5.12.1\jna-5.12.1.jar;C:\Users\tony.wijnhard\.m2\repository\net\java\dev\jna\jna-platform\5.12.1\jna-platform-5.12.1.jar;C:\Users\tony.wijnhard\.m2\repository\xuggle\xuggle-xuggler\5.4\xuggle-xuggler-5.4.jar;C:\Users\tony.wijnhard\.m2\repository\org\projectlombok\lombok\1.18.8\lombok-1.18.8.jar;C:\Users\tony.wijnhard\.m2\repository\org\apache\logging\log4j\log4j-slf4j-impl\2.18.0\log4j-slf4j-impl-2.18.0.jar;C:\Users\tony.wijnhard\.m2\repository\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;C:\Users\tony.wijnhard\.m2\repository\org\apache\logging\log4j\log4j-api\2.18.0\log4j-api-2.18.0.jar;C:\Users\tony.wijnhard\.m2\repository\org\apache\logging\log4j\log4j-core\2.18.0\log4j-core-2.18.0.jar;C:\Program Files\opencv\java\opencv-460.jar" nl.mymojo.jarvis.ai.Main
Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\Program Files\opencv\java\opencv_java460.dll: Can't find dependent libraries
	at java.base/java.lang.ClassLoader$NativeLibrary.load0(Native Method)
	at java.base/java.lang.ClassLoader$NativeLibrary.load(ClassLoader.java:2432)
	at java.base/java.lang.ClassLoader$NativeLibrary.loadLibrary(ClassLoader.java:2489)
	at java.base/java.lang.ClassLoader.loadLibrary0(ClassLoader.java:2689)
	at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2651)
	at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:827)
	at java.base/java.lang.System.loadLibrary(System.java:1871)
	at nl.mymojo.jarvis.ai.Main.<clinit>(Main.java:28)

Process finished with exit code 1

The code has been proven to execute on pre-build binaries, but without GPU acceleration which is what i am trying to acquire. I have had 1 random custom build running after trying 100s of different things. This resulted in the project executing successfully on CPU and GPU, however on GPU as soon as code forwarded a frame to dnn / yolov3 / coco; a short spike to 100% could be seen on the RTX3060 after which the program exited, without any error.

Because it was still not a 100% working environment and I had no idea how I had gotten to that point I decided to start from scratch yet again and have since not been able to get anything running at all.

Configure logs;

Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19044.
Detected processor: AMD64
libjpeg-turbo: VERSION = 2.1.3, BUILD = opencv-4.6.0-dev-libjpeg-turbo
64-bit build (x86_64)
CMAKE_ASM_NASM_COMPILER = C:/Program Files/NASM/nasm.exe
CMAKE_ASM_NASM_OBJECT_FORMAT = win64
CMAKE_ASM_NASM_FLAGS =  -DWIN64 -D__x86_64__ 
SIMD extensions: x86_64 (WITH_SIMD = 1)
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.6.0-dev-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:/Build/opencv/build/3rdparty/ippicv/ippicv_win/icv
found Intel IPP Integration Wrappers sources: 2020.0.0
at: C:/Build/opencv/build/3rdparty/ippicv/ippicv_win/iw
CUDA detected: 11.7
CUDA: Using CUDA_ARCH_BIN=8.6
CUDA NVCC target flags: -gencode;arch=compute_86,code=sm_86;-D_FORCE_INLINES
CUDA: MSVS generator is detected. Disabling CMake re-run checks (CMAKE_SUPPRESS_REGENERATION=ON). You need to run CMake manually if updates are required.
LAPACK(OpenBLAS): LAPACK_LIBRARIES: J:/OpenBLAS-0.3.21-x64/lib/libopenblas.lib
LAPACK(OpenBLAS): Support is enabled.
Found apache ant: J:/apache-ant-1.10.12/bin/ant.bat (1.10.12)
Found JNI: C:/Program Files/Java/jdk-11.0.16/include  found components: AWT JVM 
VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
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: Glog/Gflags
Tesseract:   NO
Allocator metrics storage type: 'long long'
Excluding from source files list: modules/imgproc/src/imgwarp.lasx.cpp
Excluding from source files list: modules/imgproc/src/resize.lasx.cpp
Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': C:/Build/opencv/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.rvv.cpp
Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.lasx.cpp
Excluding from source files list: <BUILD>/modules/dnn/int8layers/layers_common.lasx.cpp
imgcodecs: OpenEXR codec is disabled in runtime. Details: https://github.com/opencv/opencv/issues/21326
highgui: using builtin backend: WIN32UI
Building with NVIDIA Optical Flow API 2.0
CMake Warning at cmake/OpenCVGenSetupVars.cmake:54 (message):
  CONFIGURATION IS NOT SUPPORTED: validate setupvars script in install
  directory
Call Stack (most recent call first):
  CMakeLists.txt:1050 (include)



General configuration for OpenCV 4.6.0-dev =====================================
  Version control:               4.6.0-343-g1646a21197

  Extra modules:
    Location (extra):            C:/Build/opencv_contrib/modules
    Version control (extra):     4.6.0-75-g74fce7f7

  Platform:
    Timestamp:                   2022-10-02T10:19:02Z
    Host:                        Windows 10.0.19044 AMD64
    CMake:                       3.24.2
    CMake generator:             Visual Studio 17 2022
    CMake build tool:            C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe
    MSVC:                        1933
    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 (16 files):         + SSSE3 SSE4_1
      SSE4_2 (1 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
      FP16 (0 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
      AVX (4 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
      AVX2 (32 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
      AVX512_SKX (5 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/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.33.31629/bin/Hostx64/x64/cl.exe  (ver 19.33.31630.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 /wd4819 /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 /wd4819 /MP  /MTd /Zi /Ob0 /Od /RTC1 
    C Compiler:                  C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.33.31629/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:         YES
    Extra dependencies:          J:/OpenBLAS-0.3.21-x64/lib/libopenblas.lib wsock32 comctl32 gdi32 ole32 setupapi ws2_32 cudart_static.lib nppc.lib nppial.lib nppicc.lib nppidei.lib nppif.lib nppig.lib nppim.lib nppist.lib nppisu.lib nppitc.lib npps.lib cublas.lib cudnn.lib cufft.lib -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/lib/x64 -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v11.7/lib
    3rdparty dependencies:       libprotobuf ade ittnotify libjpeg-turbo libwebp libpng libtiff libopenjp2 IlmImf zlib quirc ippiw ippicv

  OpenCV modules:
    To be built:                 alphamat aruco barcode bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect dnn_superres dpm face features2d flann fuzzy gapi hfs highgui img_hash imgcodecs imgproc intensity_transform java 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 xfeatures2d ximgproc xobjdetect xphoto
    Disabled:                    python3 python_bindings_generator python_tests world
    Disabled by dependency:      -
    Unavailable:                 cvv freetype hdf julia matlab ovis python2 sfm viz
    Applications:                apps
    Documentation:               NO
    Non-free algorithms:         NO

  Windows RT support:            NO

  GUI:                           WIN32UI
    Win32 UI:                    YES
    VTK support:                 NO

  Media I/O: 
    ZLib:                        build (ver 1.2.12)
    JPEG:                        build-libjpeg-turbo (ver 2.1.3-62)
        SIMD Support Request:    YES
        SIMD Support:            YES
    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.134.100)
      avformat:                  YES (58.76.100)
      avutil:                    YES (56.70.100)
      swscale:                   YES (5.9.100)
      avresample:                YES (4.0.0)
    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:/Build/opencv/build/3rdparty/ippicv/ippicv_win/icv
    Intel IPP IW:                sources (2020.0.0)
              at:                C:/Build/opencv/build/3rdparty/ippicv/ippicv_win/iw
    Lapack:                      YES (J:/OpenBLAS-0.3.21-x64/lib/libopenblas.lib)
    Eigen:                       YES (ver ..)
    Custom HAL:                  NO
    Protobuf:                    build (3.19.1)

  NVIDIA CUDA:                   YES (ver 11.7, CUFFT CUBLAS)
    NVIDIA GPU arch:             86
    NVIDIA PTX archs:

  cuDNN:                         YES (ver 8.5.0)

  OpenCL:                        YES (NVD3D11)
    Include path:                C:/Build/opencv/3rdparty/include/opencl/1.2
    Link libraries:              Dynamic load

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

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

  Install to:                    C:/Program Files/opencv
-----------------------------------------------------------------

Configuring done
Generating done

I’ve been on this topic nonstop for weeks before eventually finding the forum, but at this point there is nothing left that has come to my attention from reading articles online or any logging during the build process, that indicates I’m missing something. (Apart from the obvious missing dependencies). Another reason why this error is unexpected is because I am building with shared libs unchecked as many articles suggest.

Dump of file C:\Program Files\opencv\java\opencv_java460.dll

File Type: DLL

  Image has the following dependencies:

    cublas64_11.dll
    cudnn64_8.dll
    ole32.dll
    libopenblas.dll
    KERNEL32.dll
    OLEAUT32.dll
    MFPlat.DLL
    MF.dll
    MFReadWrite.dll
    dxgi.dll
    d3d11.dll
    SHLWAPI.dll

I hope there is someone out there that can help me out, because this is really draining every last bit of moral.

For future reference:
copying cublas64_11.dll / cudnn64_8.dll / libopenblas.dll to location of opencv_java460.dll resolves this issue. However even now that a “working build” seems to have been produced, running the code with;

dnnNet.setPreferableBackend(Dnn.DNN_BACKEND_CUDA);
dnnNet.setPreferableTarget(Dnn.DNN_TARGET_CUDA);

still crashes the JVM without any errors.

17:36:26.125 [INFO ]                           jarvis.ai.Main : [main] is running ...
17:36:26.464 [INFO ]                        ai.stream.Capture : [Thread-0] is running ...
17:36:26.512 [INFO ]               ai.img.ImgProcessingEngine : [Thread-2] is running ...
17:36:27.475 [INFO ]                        ai.stream.Capture : opened mainCapture ...
17:36:28.493 [INFO ]                          ai.obj.Detector : mainCapture first frame found ...
17:36:28.709 [INFO ]                          ai.obj.Detector : detector started ...

Process finished with exit code -1073740791 (0xC0000409)

versus

17:42:54.940 [INFO ]                           jarvis.ai.Main : [main] is running ...
17:42:55.286 [INFO ]                        ai.stream.Capture : [Thread-0] is running ...
17:42:55.333 [INFO ]               ai.img.ImgProcessingEngine : [Thread-2] is running ...
17:42:56.290 [INFO ]                        ai.stream.Capture : opened mainCapture ...
17:42:57.318 [INFO ]                          ai.obj.Detector : mainCapture first frame found ...
17:42:57.538 [INFO ]                          ai.obj.Detector : detector started ...
17:42:58.729 [INFO ]               ai.img.ImgProcessingEngine : mainCapture frames incoming: 2560x1440 & 50 frames in mainCapture buffer ...
17:43:25.448 [INFO ]                        ai.stream.Metrics : mainCapture 10800 kb avg. @ 24 frames/s || imgProcessingEngine 10800 kb avg. @ 23 frames/s || detector avg; 900 kb in 1163,22ms @ 0,77 detections/s

The only difference being running on GPU vs CPU. The method eventually causing the crash is;

    public void forward(List<Mat> outputBlobs, List<String> outBlobNames) {
        Mat outputBlobs_mat = new Mat();
        forward_4(nativeObj, outputBlobs_mat.nativeObj, outBlobNames);
        Converters.Mat_to_vector_Mat(outputBlobs_mat, outputBlobs);
        outputBlobs_mat.release();
    }
1 Like