Search code examples
javac++opencvcmakeopencv3.0

Cmake cannot recognize java while building OpenCv


I'm trying to build OpenCv on Khadas Vim2, that has a pre-installed Ubuntu Mate with an arm 64 bit based cpu architecture, using CMake. However CMake is not recognizing Java (where i already have both oracle-jdk-1.8 and openjdk-1.8). I tried to reinstall Apache Ant, exporting JAVA_HOME and ANT_HOME into PATH through:

export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-arm64
export PATH=$JAVA_HOME/bin:$PATH
export ANT_HOME=/usr/local/ant
export PATH=$ANT_HOME/bin:$PATH

I also tried to set the GCC and G++ compilers in the toolchain file as:

set( CMAKE_SYSTEM_PROCESSOR arm )
set( CMAKE_C_COMPILER arm-linux-gnueabi-gcc )
set( CMAKE_CXX_COMPILER arm-linux-gnueabi-g++ )

    if(COMMAND toolchain_save_config)
      return() # prevent recursive call
    endif()

    set(CMAKE_SYSTEM_NAME Linux)
    set(CMAKE_SYSTEM_VERSION 1)
    if(NOT DEFINED CMAKE_SYSTEM_PROCESSOR)
      set(CMAKE_SYSTEM_PROCESSOR arm)
    else()
      #message("CMAKE_SYSTEM_PROCESSOR=${CMAKE_SYSTEM_PROCESSOR}")
    endif()

    include("${CMAKE_CURRENT_LIST_DIR}/gnu.toolchain.cmake")

    if(CMAKE_SYSTEM_PROCESSOR STREQUAL arm AND NOT ARM_IGNORE_FP)
      set(FLOAT_ABI_SUFFIX "")
      if(NOT SOFTFP)
        set(FLOAT_ABI_SUFFIX "hf")
      endif()
    endif()

    if(NOT "x${GCC_COMPILER_VERSION}" STREQUAL "x")
      set(__GCC_VER_SUFFIX "-${GCC_COMPILER_VERSION}")
    endif()

    if(NOT DEFINED CMAKE_C_COMPILER)
      find_program(CMAKE_C_COMPILER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-gcc${__GCC_VER_SUFFIX})
    else()
      #message(WARNING "CMAKE_C_COMPILER=${CMAKE_C_COMPILER} is defined")
    endif()
    if(NOT DEFINED CMAKE_CXX_COMPILER)
      find_program(CMAKE_CXX_COMPILER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-g++${__GCC_VER_SUFFIX})
    else()
      #message(WARNING "CMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER} is defined")
    endif()
    if(NOT DEFINED CMAKE_LINKER)
      find_program(CMAKE_LINKER NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ld${__GCC_VER_SUFFIX} ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ld)
    else()
      #message(WARNING "CMAKE_LINKER=${CMAKE_LINKER} is defined")
    endif()
    if(NOT DEFINED CMAKE_AR)
      find_program(CMAKE_AR NAMES ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ar${__GCC_VER_SUFFIX} ${GNU_MACHINE}${FLOAT_ABI_SUFFIX}-ar)
    else()
      #message(WARNING "CMAKE_AR=${CMAKE_AR} is defined")
    endif()

    if(NOT DEFINED ARM_LINUX_SYSROOT AND DEFINED GNU_MACHINE)
      set(ARM_LINUX_SYSROOT /usr/${GNU_MACHINE}${FLOAT_ABI_SUFFIX})
    endif()

    if(NOT DEFINED CMAKE_CXX_FLAGS)
      set(CMAKE_CXX_FLAGS           "" CACHE INTERNAL "")
      set(CMAKE_C_FLAGS             "" CACHE INTERNAL "")
      set(CMAKE_SHARED_LINKER_FLAGS "" CACHE INTERNAL "")
      set(CMAKE_MODULE_LINKER_FLAGS "" CACHE INTERNAL "")
      set(CMAKE_EXE_LINKER_FLAGS    "" CACHE INTERNAL "")

      set(CMAKE_CXX_FLAGS           "${CMAKE_CXX_FLAGS} -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")
      set(CMAKE_C_FLAGS             "${CMAKE_C_FLAGS} -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi")
      if(CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
        set(CMAKE_CXX_FLAGS           "-mthumb ${CMAKE_CXX_FLAGS}")
        set(CMAKE_C_FLAGS             "-mthumb ${CMAKE_C_FLAGS}")
        set(CMAKE_EXE_LINKER_FLAGS    "${CMAKE_EXE_LINKER_FLAGS} -Wl,-z,nocopyreloc")
      endif()
      if(CMAKE_SYSTEM_PROCESSOR STREQUAL arm)
        set(ARM_LINKER_FLAGS "-Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now")
      elseif(CMAKE_SYSTEM_PROCESSOR STREQUAL aarch64)
        set(ARM_LINKER_FLAGS "-Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now")
      endif()
      set(CMAKE_SHARED_LINKER_FLAGS "${ARM_LINKER_FLAGS} ${CMAKE_SHARED_LINKER_FLAGS}")
      set(CMAKE_MODULE_LINKER_FLAGS "${ARM_LINKER_FLAGS} ${CMAKE_MODULE_LINKER_FLAGS}")
      set(CMAKE_EXE_LINKER_FLAGS    "${ARM_LINKER_FLAGS} ${CMAKE_EXE_LINKER_FLAGS}")
    else()
      #message(WARNING "CMAKE_CXX_FLAGS='${CMAKE_CXX_FLAGS}' is defined")
    endif()

    if(USE_NEON)
      message(WARNING "You use obsolete variable USE_NEON to enable NEON instruction set. Use -DENABLE_NEON=ON instead." )
      set(ENABLE_NEON TRUE)
    elseif(USE_VFPV3)
      message(WARNING "You use obsolete variable USE_VFPV3 to enable VFPV3 instruction set. Use -DENABLE_VFPV3=ON instead." )
      set(ENABLE_VFPV3 TRUE)
    endif()

    set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${ARM_LINUX_SYSROOT})

    if(EXISTS ${CUDA_TOOLKIT_ROOT_DIR})
      set(CMAKE_FIND_ROOT_PATH ${CMAKE_FIND_ROOT_PATH} ${CUDA_TOOLKIT_ROOT_DIR})
    endif()

    set(TOOLCHAIN_CONFIG_VARS ${TOOLCHAIN_CONFIG_VARS}
        ARM_LINUX_SYSROOT
        ENABLE_NEON
        ENABLE_VFPV3
        CUDA_TOOLKIT_ROOT_DIR
    )
    toolchain_save_config()

but still having the following output after running the cmake command:

Command:

khadas@Khadas:~/Downloads/opencv/platforms/linux/build_hardfp$ cmake -DBUILD_SHARED_LIBRARY=OFF -DLAPACK_LIBRARIES=/usr/lib/liblapack.a -DOPENCV_EXTRA_MODULES_PATH=/home/khadas/Downloads/opencv_contrib/modules -DCMAKE_TOOLCHAIN_FILE=../arm-gnueabi.toolchain.cmake ../../..

Output:

-- General configuration for OpenCV 4.0.0-pre =====================================
--   Version control:               3.4.3-374-g475c775-dirty
-- 
--   Extra modules:
--     Location (extra):            /home/khadas/Downloads/opencv_contrib/modules
--     Version control (extra):     3.4.3-93-g3054618
-- 
--   Platform:
--     Timestamp:                   2018-09-24T09:23:39Z
--     Host:                        Linux 4.9.40 aarch64
--     Target:                      Linux 1 arm
--     CMake:                       3.5.1
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               Release
-- 
--   CPU/HW features:
--     Baseline:
--       requested:                 DETECT
--       disabled:                  VFPV3 NEON
-- 
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ Compiler:                /usr/bin/arm-linux-gnueabi-g++  (ver 5.4.0)
--     C++ flags (Release):         -mthumb  -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -mfp16-format=ieee -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -mthumb  -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Winit-self -Wsuggest-override -Wno-narrowing -Wno-delete-non-virtual-dtor -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -mfp16-format=ieee -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/arm-linux-gnueabi-gcc
--     C flags (Release):           -mthumb  -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -mfp16-format=ieee -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -mthumb  -fdata-sections -Wa,--noexecstack -fsigned-char -Wno-psabi   -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Winit-self -Wno-narrowing -Wno-comment -fdiagnostics-show-option -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -mfp16-format=ieee -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):      -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now    
--     Linker flags (Debug):        -Wl,--fix-cortex-a8 -Wl,--no-undefined -Wl,--gc-sections -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now    
--     ccache:                      NO
--     Precompiled headers:         NO
--     Extra dependencies:          dl m pthread rt
--     3rdparty dependencies:
-- 
--   OpenCV modules:
--     To be built:                 aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dpm face features2d flann fuzzy hfs highgui img_hash imgcodecs imgproc java_bindings_generator line_descriptor ml objdetect optflow phase_unwrapping photo plot python_bindings_generator reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    js world
--     Disabled by dependency:      -
--     Unavailable:                 cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv freetype hdf java matlab ovis python2 python3 sfm viz
--     Applications:                tests perf_tests apps
--     Documentation:               NO
--     Non-free algorithms:         NO
-- 
--   GUI: 
--     GTK+:                        NO
-- 
--   Media I/O: 
--     ZLib:                        build (ver 1.2.11)
--     JPEG:                        libjpeg-turbo (ver 1.5.3-62)
--     WEBP:                        build (ver encoder: 0x020e)
--     PNG:                         build (ver 1.6.34)
--     TIFF:                        build (ver 42 - 4.0.9)
--     JPEG 2000:                   build (ver 1.900.1)
--     OpenEXR:                     build (ver 1.7.1)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
-- 
--   Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      NO
--       avcodec:                   NO
--       avformat:                  NO
--       avutil:                    NO
--       swscale:                   NO
--       avresample:                NO
--     GStreamer:                   NO
--     libv4l/libv4l2:              NO
--     v4l/v4l2:                    linux/videodev2.h
-- 
--   Parallel framework:            pthreads
-- 
--   Trace:                         YES (built-in)
-- 
--   Other third-party libraries:
--     Lapack:                      NO
--     Custom HAL:                  YES (carotene (ver 0.0.1))
--     Protobuf:                    build (3.5.1)
-- 
--   OpenCL:                        YES (no extra features)
--     Include path:                /home/khadas/Downloads/opencv/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
-- 
--   Python (for build):            /usr/bin/python2.7
-- 
--   Install to:                    /home/khadas/Downloads/opencv/platforms/linux/build_hardfp/install
-- -----------------------------------------------------------------
-- 
-- Configuring done
-- Generating done

Please consider the following line in the output under Opencv Models:

--     Unavailable:                 cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv freetype hdf java matlab ovis python2 python3 sfm viz

Thanks in advance!!


Solution

  • I don't think this will be the best way to solve this problem, but i solve it this way:

    1. installing cmake-gui (sudo apt-get install cmake-gui)
    2. removing the content of the build folder (to start again)
    3. start cmake-gui and configure the build
    4. enable BUILD_JAVA param
    5. add new entry titled JAVA_HOME that points to the java home directory
    6. configure build again

    then cmake successfully recognized java